Page 1 of 1

Form field info after a post

Posted: Mon Sep 29, 2003 9:49 am
by phpnewb33
I am trying to create a dynamic select query based on a list of form elements submitted from the previous screen.

What i wold like to do is loop through the submitted fields and compare them to the fields in a db table with the same names. I can easily get the values from the fields, but i cannot find the function or variable to get the array of form field names.

Can anyone point me in the right direction?

Thanks!

Posted: Mon Sep 29, 2003 11:39 am
by styrmstread
if i understand you correctly, here is what you can do,

if the form is submitted by the POST method use the following to loop through these form fields.

Code: Select all

while (list($var,$val) = each($HTTP_POST_VARS))
         { ....}
In this case $var is the formfield name, and $val is the value associated with this field.
Once in this loop you can check names using something like

Code: Select all

if (ereg("^nnn",$var,$throwaway))
  {   
   ....
  }
ereg checks $var to see if nnn are the first three characters of its value.
you can then perform your process conditionally dependent upon which form field $var is pointing to.
I hope this makes sense...let me know if you don't understand.
Styrmstread

Posted: Mon Sep 29, 2003 12:28 pm
by phpnewb33
styrmstread,

Thanks for your help! This is exactly what i needed...

-gary

Posted: Mon Sep 29, 2003 5:33 pm
by junky
what to say more ? except that styrmstread is a good teacher :)

$_POST isnt the new standard replacing the $HTTP_POST_VARS ? 8)