The simplest way to create valid AJAX forms for your website.
This is the code used in the example form. As you can see it only took 16 lines of simple PHP code to make the whole form.
Once you have downloaded the PHP AJAX Form Producer you need to drop the "form_producer" folder somewhere on your server.
Once you have done this open up the page you want to add the Form Producer to and add the following PHP to the top of the page:
<?php require_once ('url/to/form_producer/form_producer.php'); $form_prod_url = 'url/to/form_producer'; //Create Your Form Here ?>
Make sure you set the
$form_prod_url to the location of the "form_producer" folder relative to the file you are editing.
Finally you need to include jQuery in your HTML (usually somewhere in your
Note: Here we are including the hosted version of jQuery via Google API's. If you do it this way you don't need to download jQuery.
As you can see in the code it is really easy to create your forms. There are three functions you can use to create your forms:
add_fieldset($id, [ $legend ])
This function creates a fieldset in your form and allows you to group form elements. It requires you specify an id and you also have the option to define the legend (which defualts to "").
add_form_element($fieldset, $name, [ $type, $value, $required ])
This function creates a form element. It requires you specify a fieldset id (see above) and a name for your form element. The other variables in this function are as follows:
This function allows you to insert normal text at any point in your form. It requires you set a fieldset id (see above) and a value for your text.
There is one final function you need to use to output your form:
<?php generate_form(); ?>
You must put this where you want to output your form. You can only create one form per page so this can only be called once and must called after you have used the above functions to create your form. See the exmaple code to get a better understanding of where things need to be placed.
In this example we are simply emailing the results of the form using the email_processor.php file in the "form_producer" folder. However you might want to create a custom processor to process the data in other ways. For example you might want to insert your form data into a MySQL database.
To create a custom form processor you need to create a new file in the "form_producer" folder (e.g. database_processor.php). You then need to set the following config value to make sure the AJAX call is sent to the right processor:
<?php require_once ('url/to/form_producer/form_producer.php'); $form_prod_url = 'url/to/form_producer'; $form_processor = 'database_processor.php'; //Create Your Form Here ?>
Now the AJAX post will be sent to the database_processor.php file. You can then use the
$_POST PHP array to retrieve your values in this file. See the email_processor.php
file for an example.