Jun 13th, 2012, 3:41 AM
(This post was last modified: Jun 13th, 2012, 3:46 AM by Question Guy.)
So, I finally took this online and it WORKS! Even though my Test Email function on my localhost worked, apparently something in the FormTools configuration can't handle localhost email.
The localhost environment always sends emails correctly out to the internet but the Test Email function in FormTools Settings is apparently disconnected from the actual process for a Live External Form. Once I installed this ONLINE at a server then the form advanced to the "thank you" page!
NOW, I am trying to solve an API Form validation problem.
In a nutshell: As soon as I added PHP Validation rules into my form that specified that 3 of my fields had to have a length of 6 characters but no greater than 6 then the PHP errors returned IF any of those fields were NOT filled out.
But, I am not running a REQUIRED rule on those fields. I simply want any values, if entered, into those 3 fields to be no less than 6 characters in length and no more than 6 characters in length.
But this Rule is now making each of those fields REQUIRED on this form submission.
What the PHP should be saying as part of the rule is that "IF there is a Posted Value for this field then the Following Rule on Minimum and Maximum Length ought to be Applied ELSE this particular Rule does not run for this field".
Here is the script that is now Reporting an Error when No Value is Posted into the Guess1, Guess2, Guess3 field. It also contains a Login test script at the top.
The localhost environment always sends emails correctly out to the internet but the Test Email function in FormTools Settings is apparently disconnected from the actual process for a Live External Form. Once I installed this ONLINE at a server then the form advanced to the "thank you" page!
NOW, I am trying to solve an API Form validation problem.
In a nutshell: As soon as I added PHP Validation rules into my form that specified that 3 of my fields had to have a length of 6 characters but no greater than 6 then the PHP errors returned IF any of those fields were NOT filled out.
But, I am not running a REQUIRED rule on those fields. I simply want any values, if entered, into those 3 fields to be no less than 6 characters in length and no more than 6 characters in length.
But this Rule is now making each of those fields REQUIRED on this form submission.
What the PHP should be saying as part of the rule is that "IF there is a Posted Value for this field then the Following Rule on Minimum and Maximum Length ought to be Applied ELSE this particular Rule does not run for this field".
Here is the script that is now Reporting an Error when No Value is Posted into the Guess1, Guess2, Guess3 field. It also contains a Login test script at the top.
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.";
$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.";
$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.";
$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);
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Vipcontest Guess Form</title>
</head>
<body>
<table width="85%" border="0" align="center" cellpadding="10">
<tr>
<th scope="col"> </th>
<th scope="col"> </th>
</tr>
<tr>
<td colspan="2"><form action="http://www.mywebsite.com/formtools/modules/submission_accounts/login.php" method="post">
<input type="hidden" name="form_id" value="1" />
<input type="hidden" name="invalid_login_redirect_url" value="http://www.mywebsite.com/loginfail.php" />
Email <input type="text" name="username" /><br />
Password <input type="text" name="password" /><br />
<input type="submit" name="login" value="LOGIN" /><br />
<a href="http://www.mywebsite.com/formtools/modules/submission_accounts/forget_password.php">Forget your password?</a><br />
</form></td>
</tr>
<tr>
<th scope="col"><?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'>Please fix the following errors:\n<ul>";
foreach ($errors as $error)
echo "<li>$error</li>\n";
echo "</ul></div>";
}
?></th>
<th scope="col"> </th>
</tr>
<tr>
<td colspan="2"><form name = "Vipcontest" id= "Vipcontest" action="<?php echo $_SERVER["PHP_SELF"]?>" method="POST">
<p>First Name
<input name="fname" type="text" id="fname" value="<?=htmlspecialchars(@$fields["fname"])?>" />
</p>
<p>Last Name
<input name="lname" type="text" id="lname" value="<?=htmlspecialchars(@$fields["lname"])?>" />
</p>
<p>City
<input name="city" type="text" id="city" value="<?=htmlspecialchars(@$fields["city"])?>" />
</p>
<p>Email
<input name="email" type="text" id="email" value="<?=htmlspecialchars(@$fields["email"])?>" />
</p>
<p>First Guess
<input name="guess1" type="text" id="guess1" value="<?=htmlspecialchars(@$fields["guess1"])?>" />
</p>
<p>Second Guess
<input name="guess2" type="text" id="guess2" value="<?=htmlspecialchars(@$fields["guess2"])?>" />
</p>
<p>Third Guess
<input name="guess3" type="text" id="guess3" value="<?=htmlspecialchars(@$fields["guess3"])?>" />
</p>
<p>Password
<input name="password" type="text" id="password" value="<?=htmlspecialchars(@$fields["password"])?>" />
</p>
<p> </p>
<p>Submit
<input type="submit" name="sendguess" id="sendguess" value="Submit" />
</p>
</form>
</td>
</tr>
</table>
</body>
</html>