|  | Posted by planotravel.net on 06/25/06 04:02 
h7qvnk7q001 wrote:> I'm trying to implement a simple server-side form validation (No
 > Javascript).  If the user submits a form with errors, I want to
 > redisplay the same form with the errors highlighted. Once the form is
 > correct I need to submit to another page that uses the form data.
 
 My solution for the recently started project was the following:
 
 Create three .php files
 
 1.php - (to initialize form variables) with a call to an A(2) function
 in 2.php with default parameters (0 for error variable, and an array of
 form elements)
 - 1.php is called when the user enters the form page
 
 2.php - (to print out and control the form) with the A(2) function that
 takes those two arguments
 - echo "<form action=3.php method=post>";
 - for each required field use:
 if ($error & n).{ echo "..."; }  //where n is an error bit, e.g.,
 1,2,4,8,16,32 and so on.
 else { echo "..."; }
 - for all fields use interpolated array[x] value to , e.g., echo
 "<input type=text value=\"{$array["value"]}\">; - to return any
 previously entered data after page reload
 
 3.php - with a B() form validation function (checker) that is first
 called in 3.php
 - create, initialize and fill out the $array of form variables with
 user input
 - $error = 0; check the form data, assign $error a bit (1,2,4,8 etc.)
 if an error is found
 - if ($error != 0) { A(2); } else { do smth.,e,g, C(a,b,c); }
 
 
 - in 1.php and 3.php first do
 include '2.php';
 
 
 PS Go to http://www.planotravel.net, request a quote (yellow image),
 randomly fill out the form with errors, submit and see how it works.
 
 Good luck and Regards,
 
 planotravel.net
  Navigation: [Reply to this message] |