Configuring the First Form Page
From the API's viewpoint, the first page in your form is special. It lets the script know that a new user has just arrived and to start logging their form submission as they progress through the form. Add this to the very top of your page (before the opening html tag and doctype), and make a few minor modifications to it, as discussed below:
{* highlight php %} "submit_button_name_attribute", "next_page" => "next_page.php", "form_data" => $_POST ); ft_api_process_form($params); ?> {* endhighlight %}- The path to the api.php file has to be updated for your server
- Change "submit_button_name_attribute" to the name attribute of your form submit button
- Change "next_page.php" to the SECOND page in your multi-page form. This is where the user gets directed to after submitting this page.
-
If your form contains file fields, add one more parameter to the $params array: the last
file_data row.
$params = array( "submit_button" => "submit_button_name_attribute", "next_page" => "next_page.php", "form_data" => $_POST, "file_data" => $_FILES );
Next, make sure your form tag has the following action and method attributes:
<form action="<?php echo $_SERVER["PHP_SELF"]?>" method="POST">
$_SERVER["PHP_SELF"] is just a PHP value for the location of the current page. This makes the form submit the information to itself. The ft_api_process_form() function will take care of redirecting to the next page. One of the nice things about posting the submission to itself is that if later on, you choose to add server-side validation (see this tutorial), it's much easier to handle the errors on the same page.
Tip: it's generally a better idea to use $_SERVER["PHP_SELF"] instead of the name of the file, since filenames sometimes change. If that happens, you'd need to remember to update the action attribute. But by using the PHP variable, you don't have to worry about it!
With regard to the form's post attribute, if you want to use method="GET", that's fine - just change the PHP line in the top of the from:
"form_data" => $_POST,
"form_data" => $_GET,