Hi
I have a small test for that i am trying to get to keep the data thats entered and refill after a failed validation.
The form will validate just fine and reports the error but will not keep the Form data
Here is the sample of the code attached.any help with getting the form to re populate the fields on a error would be great
<?php
require_once("forms2/global/api/api.php");
$fields = ft_api_init_form_page(10);
$errors = array();
if (isset($_POST['submit']))
{
$rules = array();
$rules[] = "required,name,Please enter your name.";
$rules[] = "required,email,Please enter your email address.";
$rules[] = "valid_email,email,Please enter a valid email address.";
$rules[] = "required,comments,Please enter your comments.";
$errors = validate_fields($_POST, $rules);
if (empty($errors))
{
$params = array(
"submit_button" => "submit",
"next_page" => "thanks.php",
"form_data" => $_POST,
"file_data" => $_FILES,
"finalize" => true
);
ft_api_process_form($params);
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>
<body>
<?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>";
}
?>
<form action="<?php echo $_SERVER["PHP_SELF"]?>" method="POST">
<td>
<p class="ft_font">Items Marked with a * are required fields
<hr size="1" style="width: 500px" class="style1" />
</p>
<table cellpadding="2" width="700" height="299" border="1" style="border-collapse: collapse" bordercolor="#808000">
<input type="hidden" name="NanProperties Contact Us" value="hidden" />
<tr>
<td class="required_field">*</td>
<td><b>Name</b></td>
<td class="answer"height="19">
<input type="text" name="name" maxlength="50" style="width:175px" <?php echo htmlspecialchars(@$fields['name']); ?> /></td>
</tr>
<tr>
<td class="required_field">*</td>
<td><b>Email</b></td>
<td class="answer"height="19"><input type="text" name="email" maxlength="20" style="width:150px" <?php echo htmlspecialchars(@$fields['email']); ?>/></td>
</tr>
<td class="required_field"></td>
<td><strong><font size="1">Please enter
</font>
</strong>
<font size="1">
<strong>Security Code:</strong>
</font>
</td>
<td class="answer"height="19"></td>
<tr>
<td></td>
<td><b>Comments</b></td>
<td class="answer"height="193">
<textarea name="comments" <?php echo htmlspecialchars(@$fields['comments']); ?> style="width: 319; height: 158"></textarea>/></td>
</tr>
</table>
<p><input type="submit" name="submit" value="Submit" style="float: center"></p>
</body>
</html>
Thanks Robotech
I have a small test for that i am trying to get to keep the data thats entered and refill after a failed validation.
The form will validate just fine and reports the error but will not keep the Form data
Here is the sample of the code attached.any help with getting the form to re populate the fields on a error would be great
<?php
require_once("forms2/global/api/api.php");
$fields = ft_api_init_form_page(10);
$errors = array();
if (isset($_POST['submit']))
{
$rules = array();
$rules[] = "required,name,Please enter your name.";
$rules[] = "required,email,Please enter your email address.";
$rules[] = "valid_email,email,Please enter a valid email address.";
$rules[] = "required,comments,Please enter your comments.";
$errors = validate_fields($_POST, $rules);
if (empty($errors))
{
$params = array(
"submit_button" => "submit",
"next_page" => "thanks.php",
"form_data" => $_POST,
"file_data" => $_FILES,
"finalize" => true
);
ft_api_process_form($params);
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>
<body>
<?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>";
}
?>
<form action="<?php echo $_SERVER["PHP_SELF"]?>" method="POST">
<td>
<p class="ft_font">Items Marked with a * are required fields
<hr size="1" style="width: 500px" class="style1" />
</p>
<table cellpadding="2" width="700" height="299" border="1" style="border-collapse: collapse" bordercolor="#808000">
<input type="hidden" name="NanProperties Contact Us" value="hidden" />
<tr>
<td class="required_field">*</td>
<td><b>Name</b></td>
<td class="answer"height="19">
<input type="text" name="name" maxlength="50" style="width:175px" <?php echo htmlspecialchars(@$fields['name']); ?> /></td>
</tr>
<tr>
<td class="required_field">*</td>
<td><b>Email</b></td>
<td class="answer"height="19"><input type="text" name="email" maxlength="20" style="width:150px" <?php echo htmlspecialchars(@$fields['email']); ?>/></td>
</tr>
<td class="required_field"></td>
<td><strong><font size="1">Please enter
</font>
</strong>
<font size="1">
<strong>Security Code:</strong>
</font>
</td>
<td class="answer"height="19"></td>
<tr>
<td></td>
<td><b>Comments</b></td>
<td class="answer"height="193">
<textarea name="comments" <?php echo htmlspecialchars(@$fields['comments']); ?> style="width: 319; height: 158"></textarea>/></td>
</tr>
</table>
<p><input type="submit" name="submit" value="Submit" style="float: center"></p>
</body>
</html>
Thanks Robotech