plugin that processes forms

I am trying to write a plugin that will be able to process four or five different forms, some of which will print the result to the page, and some of which will print it through AJAX. What is the best way to do this?

I have looked at several plugins that process forms, and they all seem to do it differently:
comment_form has action="#" and I can't figure out where the code that process the form is located
contact_form has action=$_SERVER['REQUEST_URI'], and I can't figure out where the code that processes the form is located
rating has action="submit" and the processing appears to be done by the update.php file
register_user has action=register_user and the code appears to be in the plugin file itself. However, when I try this, the code runs every time

Can someone give me some pointers on how to do this?

Thanks.

Comments

  • acrylian Administrator, Developer
    comment_form: The code that actually processes the comment post is within the core in `zp-core/functions-controller.php`.

    contact_form: The plugin itself has the code that processes the form, however the actual mail function is a core one as well, in `zp-core/functions.php`.

    So how you process your form is therefore dependend on what you want to do actually with that form.
  • More to the point, it depends on how you include the form html in your theme/plugin.

    The comment "form" itself if included in the comment plugin script. So the action="#" will take you to that script and the processing gets done there.

    The contact "form" is included by a theme script "somewhere" (of coures we do not know ahead of time where that will be.) Thus it has to create that URI so the post gets processed when the script gets loaded. (The plugin actually processes the post when it is loaded during the script load.)

    So, if your plugin has an independent script page, that page can handle the POST. If it is dependent on the theme, then you will have to do something like the contact form plugin does.
Sign In or Register to comment.