i've been beating my brains out on my moniter because i cant figure out what is wrong with my code. what i am doing is checking input from a form to make sure it is accurate and if it isn't then i print a new table row and tell the people which fields they need to change and apperently i am too stupid to figure this out (mabey cause my brains are scattered accross my office.)
anyway code section one form valiadation on remote php mailer page ron and Motoma helped me with this code. but it is alot different than what they posted
code summary
i start my session and set my $_SESSION[failed] to zero, this will be set to one if an invalid form entry is entered. $i is a counter that will set a $_SESSION variable to equal the form area inproperly filled out, the thanksurl thing is just my redirect url if there isn't an error then i mail this form and it goes to a confermation page.
Expand|Select|Wrap|Line Numbers
- session_start();
- $_SESSION[failed]=0;
- $i=1;
- while ($i<9)
- {
- }
- $ThanksURL = 'submitted.htm';
- if (strlen(trim($_POST[email])) < 1)
- {
- $_SESSION[failed] = 1;
- $_SESSION[$i] = 'email';
- $i++;
- $ThanksURL= "registration.php";
- }
- if (strlen(trim($_POST[first_name])) < 1)
- {
- $_SESSION[failed] = 1;
- $_SESSION[$i] = 'First Name';
- $i++;
- $ThanksURL= "registration.php";
- }
- if (strlen(trim($_POST[last_name])) < 1)
- {
- $_SESSION[failed] = 1;
- $_SESSION[$i] = 'Last Name';
- $i++;
- $ThanksURL= "registration.php";
- }
- if (strlen(trim($_POST[address])) < 1)
- {
- $_SESSION[failed] = 1;
- $_SESSION[$i] = 'Address';
- $i++;
- $ThanksURL= "registration.php";
- }
- if (strlen(trim($_POST[city])) < 1)
- {
- $_SESSION[failed] = 1;
- $_SESSION[$i] = 'City';
- $i++;
- $ThanksURL= "registration.php";
- }
- if (strlen(trim($_POST[state])) < 1)
- {
- $_SESSION[failed] = 1;
- $_SESSION[$i] = 'State';
- $i++;
- $ThanksURL= "registration.php";
- }
- if (strlen(trim($_POST[zip_code])) < 1)
- {
- $_SESSION[failed] = 1;
- $_SESSION[$i] = 'Zip Code';
- $i++;
- $ThanksURL= "registration.php";
- }
- if (strlen(trim($_POST[how_much_submit])) < 1)
- {
- $_SESSION[failed] = 1;
- $_SESSION[$i] = 'Submission Amount';
- $i++;
- $ThanksURL= "registration.php";
- }
code summary
the $_SESSION[fialed] variable will determine if the person has failed to fill out this form once before.
the loop then goes through all of the errors that i assigned earlier, exaple if they forgot to fill out the first name and zip code portions then $_SESSION[1] would be set to 'first name' and $_SESSION[2] would be set to 'zip code'
Expand|Select|Wrap|Line Numbers
- <?
- if ($_SESSION[failed] = 1)
- {
- echo "<tr>";
- echo "<td>";
- echo "please fill in the ";
- $i = 1;
- while (isset($_SESSION[$i]))
- {
- echo $_SESSION[$i] " ";
- $i++;
- }
- echo "fields";
- echo "</td>";
- echo "</tr>";
- }
- ?>
when i just open the file on my computer it showes bits of the php code at the top of my form here is the jumble of mess it displays
"; echo ""; echo ""; } ?>
"; echo "please fill in the "; $i = 1; while (isset($_SESSION[$i])) { echo $_SESSION[$i] " "; $i++; } echo "fields"; echo "
Thanks for any and all help
eric