Jun 13th, 2012, 8:36 AM
OKAY, another problem SOLVED.
I have made the PHP server side validation Conditional for the 3 fields that were giving me problems because attaching character length validation code to those 3 fields was making them Required.
I have modified the code to the following so that the form will allow the user to simply leave the fields blank when the form is processed after Submit using the external form API.
Here is the code that solves the problem for me.
I have made the PHP server side validation Conditional for the 3 fields that were giving me problems because attaching character length validation code to those 3 fields was making them Required.
I have modified the code to the following so that the form will allow the user to simply leave the fields blank when the form is processed after Submit using the external form API.
Here is the code that solves the problem for me.
PHP Code:
<?php
require_once("formtools/global/api/api.php");
$fields = ft_api_init_form_page(1);
// validation time!
$errors = array();
if (isset($_POST['sendguess']))
{
$rules = array();
$rules[] = "required,email,Please enter your email address.";
$rules[] = "valid_email,email,Please enter a valid email address.";
if(!empty($_POST['guess1'])) {
$rules[] = "digits_only,guess1, Please only enter numbers with no commas.";
$rules[] = "length=6-7,guess1, No less or more than 6 numbers -- Guess 1 number is greater than 6 digits -- please keep your guess within 6 digits total.";
}
if(!empty($_POST['guess2'])) {
$rules[] = "digits_only,guess2, Please only enter numbers with no commas.";
$rules[] = "length=6-7,guess2, No less or more than 6 numbers -- Guess 2 is greater than 6 digits-- please keep your guess within 6 digits total.";
}
if(!empty($_POST['guess3'])) {
$rules[] = "digits_only,guess3, Please only enter numbers with no commas.";
$rules[] = "length=6-7,guess3, No less or more than 6 numbers -- Guess 3 is greater than 6 digits-- please keep your guess within 6 digits total.";
}
$errors = validate_fields($_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" => "sendguess",
"next_page" => "thanks.php",
"form_data" => $_POST,
"finalize" => true
);
ft_api_process_form($params);
}
// it failed validation. Update $fields with the latest contents of the form data
else
{
$fields = array_merge($_SESSION["form_tools_form"], $_POST);
}
}
?>