Jul 13th, 2009, 6:31 AM
There are three chunks of PHP--
1) The PHP to process the form through Form Tools API
2) The PHP to perform server-side validation with your PHP Validation - v2.3.1 code
3) Another chunk of PHP inserted in the form to display the errors (?)
I don't understand how to integrate these PHP snippets and have tried everything I can think of to get this to work and am having no success. And without server-side validation, everything fails miserably if the enduser does not have javascript enabled which means this was all for naught. :-(
Also, no success messages should be output if validation is successful--it should just carry on to the thank you page and do what it's supposed to do so I don't know how to extract that stuff from the third chunk.
I'd really like to be able to use Form Tools--you did such a fantastic job with this and I want to be able to use it!!
CHUNK #1: FORM TOOLS PHP API CODE AT TOP OF FORM
__________________________________________________________________________
CHUNK #2: PHP FOR FORM VALIDATION
__________________________________________________________________________
CHUNK #3: MORE PHP FOR INCLUSION IN THE FORM AS A RESULT OF VALIDATION.PHP (?)
1) The PHP to process the form through Form Tools API
2) The PHP to perform server-side validation with your PHP Validation - v2.3.1 code
3) Another chunk of PHP inserted in the form to display the errors (?)
I don't understand how to integrate these PHP snippets and have tried everything I can think of to get this to work and am having no success. And without server-side validation, everything fails miserably if the enduser does not have javascript enabled which means this was all for naught. :-(
Also, no success messages should be output if validation is successful--it should just carry on to the thank you page and do what it's supposed to do so I don't know how to extract that stuff from the third chunk.
I'd really like to be able to use Form Tools--you did such a fantastic job with this and I want to be able to use it!!
CHUNK #1: FORM TOOLS PHP API CODE AT TOP OF FORM
Code:
<?php
require_once("/path/to/form/global/api/api.php");
$fields = ft_api_init_form_page(3);
$params = array(
"submit_button" => "send",
"next_page" => "thanks.php",
"form_data" => $_POST,
"finalize" => true
);
ft_api_process_form($params);
?>
CHUNK #2: PHP FOR FORM VALIDATION
Code:
<?php
$errors = array(); // set the errors array to empty, by default
$fields = array(); // stores the field values
$success_message = "";
if (isset($_POST['submit']))
{
// import the validation library
require("validation.php");
$rules = array(); // stores the validation rules
// standard form fields
$rules[] = "required,user_name,This field is required.";
$rules[] = "required,email,Please enter your email address.";
$rules[] = "valid_email,email,Please enter a valid email address.";
$errors = validateFields($_POST, $rules);
// if there were errors, re-populate the form fields
if (!empty($errors))
{
$fields = $_POST;
}
// no errors! redirect the user to the thankyou page (or whatever)
else
{
$message = "All fields have been validated successfully!";
// here you would either email the form contents to someone or store it in a database.
// To redirect to a "thankyou" page, you'd just do this:
// header("Location: thanks.php");
}
}
?>
__________________________________________________________________________
CHUNK #3: MORE PHP FOR INCLUSION IN THE FORM AS A RESULT OF VALIDATION.PHP (?)
Code:
<?php
// if $errors is not empty, the form must have failed one or more validation
// tests. Loop through each and display them on the page for the user
if (!empty($errors))
{
echo "<div class='error' style='width:100%;'>Please fix the following errors:\n<ul>";
foreach ($errors as $error)
echo "<li>$error</li>\n";
echo "</ul></div>";
}
if (!empty($message))
{
echo "<div class='notify'>$success_message</div>";
}
?>