By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,642 Members | 1,672 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,642 IT Pros & Developers. It's quick & easy.

telling people which inputs they missed on a form

tolkienarda
100+
P: 316
hi all

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
  1.     session_start();
  2.     $_SESSION[failed]=0;
  3.     $i=1;
  4.     while ($i<9)
  5.     {
  6.  
  7.     }
  8.     $ThanksURL = 'submitted.htm';
  9.     if (strlen(trim($_POST[email])) < 1)
  10.     {
  11.     $_SESSION[failed] = 1;
  12.     $_SESSION[$i] = 'email';
  13.     $i++;
  14.     $ThanksURL= "registration.php";
  15.     }
  16.  
  17.     if (strlen(trim($_POST[first_name])) < 1)
  18.     {
  19.     $_SESSION[failed] = 1;
  20.     $_SESSION[$i] = 'First Name';
  21.     $i++;
  22.     $ThanksURL= "registration.php";
  23.     }
  24.  
  25.     if (strlen(trim($_POST[last_name])) < 1)
  26.     {
  27.     $_SESSION[failed] = 1;
  28.     $_SESSION[$i] = 'Last Name';
  29.     $i++;
  30.     $ThanksURL= "registration.php";
  31.     }
  32.  
  33.     if (strlen(trim($_POST[address])) < 1)
  34.     {
  35.     $_SESSION[failed] = 1;
  36.     $_SESSION[$i] = 'Address';
  37.     $i++;
  38.     $ThanksURL= "registration.php";
  39.     }
  40.  
  41.     if (strlen(trim($_POST[city])) < 1)
  42.     {
  43.     $_SESSION[failed] = 1;
  44.     $_SESSION[$i] = 'City';
  45.     $i++;
  46.     $ThanksURL= "registration.php";
  47.     }
  48.  
  49.     if (strlen(trim($_POST[state])) < 1)
  50.     {
  51.     $_SESSION[failed] = 1;
  52.     $_SESSION[$i] = 'State';
  53.     $i++;
  54.     $ThanksURL= "registration.php";
  55.     }
  56.  
  57.     if (strlen(trim($_POST[zip_code])) < 1)
  58.     {
  59.     $_SESSION[failed] = 1;
  60.     $_SESSION[$i] = 'Zip Code';
  61.     $i++;
  62.     $ThanksURL= "registration.php";
  63.     }
  64.  
  65.     if (strlen(trim($_POST[how_much_submit])) < 1)
  66.     {
  67.     $_SESSION[failed] = 1;
  68.     $_SESSION[$i] = 'Submission Amount';
  69.     $i++;
  70.     $ThanksURL= "registration.php";
  71.     }
  72.  
up next the messy loop that tells people which fields they missed on their first try.

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
  1. <?
  2. if ($_SESSION[failed] = 1)
  3. {
  4. echo "<tr>";
  5. echo "<td>";
  6. echo "please fill in the&nbsp;";
  7. $i = 1;
  8. while (isset($_SESSION[$i]))
  9. {
  10. echo $_SESSION[$i] "&nbsp";
  11. $i++;
  12. }
  13. echo "fields";
  14. echo "</td>";
  15. echo "</tr>";
  16. }
  17. ?>
  18.  
  19.  
Now the problem i am having is when i upload the page nothing displays and when i view the source code it is also blank.
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
Jan 31 '07 #1
Share this Question
Share on Google+
2 Replies


tolkienarda
100+
P: 316
hi

ok so i found a few problems which seem to fix that problem

the problem was in my display script where i try to make a new tr and td. apparently that isn't allowed but anyway now the page will load online but it is still going into that first if statement where i ask if $_SESSION[failed] is equal 1 now i am just comming back to my form page after i click the button and the error message dosen't tell me which form fields are incorrect. i have added another equal sign in my if statement because i had to when i used to program in c++ but it didnt help.

i changed the form valation script to take out the empty loop

if you are confused by my question because i tend to ramble and get spacy post calling me stupid and i will try to refrase everything
Jan 31 '07 #2

tolkienarda
100+
P: 316
I don't know how to delete my post but this one is has so much crap in it that you should just ignore it and i will repost sometime when i am thinking straight.

sorry
eric
Feb 1 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.