The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 871 - File: showthread.php PHP 7.4.15 (Linux)
File Line Function
/showthread.php 871 errorHandler->error



FORUMS


The Form Tools forums are no longer active, but the old posts have been archived here. Please see the Help page on how to get help / report issues.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
keeping form data on error validation
#1
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
Reply


Messages In This Thread
keeping form data on error validation - by robotech - Oct 9th, 2009, 3:11 PM
RE: keeping for data on error validation - by msaz87 - Oct 9th, 2009, 11:12 PM
RE: keeping for data on error validation - by robotech - Oct 10th, 2009, 3:08 PM
RE: keeping form data on error validation - by msaz87 - Oct 10th, 2009, 4:50 PM
RE: keeping form data on error validation - by msaz87 - Mar 31st, 2012, 7:29 PM
RE: keeping form data on error validation - by msaz87 - Jul 23rd, 2012, 1:50 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)