Hey Ruby!
Don't worry - we can get this sorted.
Basically it's just a matter of juggling the PHP logic to get it straight. Based on what you've posted, here's how the code would look. By the way, don't worry about the 3rd chunk: the error message display - that will remain where it is, unaffected.
I trimmed a lot of the unnecessary logic, so hopefully this will make it a little clearer. Things like including the validation.php file is already taken care of for us when we included the api.php, and all the manual stuff of storing the data in the $fields var is already done by ft_api_init_form_page(). Nice!
Hmm... but I must say, this REALLY makes me realize that the server-side validation tutorial is needed... okay, another project for this weekend. :-)
Let me know if the above doesn't work for you, or if you run into any other problems!
- Ben
Don't worry - we can get this sorted.
Basically it's just a matter of juggling the PHP logic to get it straight. Based on what you've posted, here's how the code would look. By the way, don't worry about the 3rd chunk: the error message display - that will remain where it is, unaffected.
PHP Code:
<?php
require_once("/path/to/form/global/api/api.php");
$fields = ft_api_init_form_page(3);
// validation time!
$errors = array();
if (isset($_POST['submit']))
{
$rules = array(); // stores the validation rules
$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);
// no errors - great! Now we process the page. The ft_api_process_form does
// the job of both updating the database and redirecting to the next page
if (empty($errors))
{
$params = array(
"submit_button" => "send",
"next_page" => "thanks.php",
"form_data" => $_POST,
"finalize" => true
);
ft_api_process_form($params);
}
}
?>
I trimmed a lot of the unnecessary logic, so hopefully this will make it a little clearer. Things like including the validation.php file is already taken care of for us when we included the api.php, and all the manual stuff of storing the data in the $fields var is already done by ft_api_init_form_page(). Nice!
Hmm... but I must say, this REALLY makes me realize that the server-side validation tutorial is needed... okay, another project for this weekend. :-)
Let me know if the above doesn't work for you, or if you run into any other problems!
- Ben