Forum Moderators: coopster

Message Too Old, No Replies

PHP Identify Which Form You Are On

         

stidj

8:30 pm on Aug 5, 2005 (gmt 0)

10+ Year Member



I have a dynamic script which will basically echo 1 of 3 forms based on the submit value.

The question is since I eventually end up storing this all into cookies and users may need to go back to other forms, I want to write the cookies back into the forms. I know how to do this, but the issue is how can you identify what form you are actually displaying to know which cookies should be used?

eg. the problem occurs here.
Say form 1 has a submit button called "Form1"

My script decides which form to display based on that, and I was trying to also use that to determine what cookies should be used.

It doesn't work because you could have clicked Submit on Form1 and the Submit value it is "Form1" so the cookies would be called as we are on Form 1 but really we are on Form 2.

Anyone have an idea on how to set up variables or some way to uniquely identify each form so we can figure out which cookies to use?

Thanks

coopster

12:49 am on Aug 6, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I'm a bit confused here, stidj. If you dished up the page in the first place, how can you not know which form they are on?

vincevincevince

9:57 am on Aug 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In each and every form field, write it as:

<input name="blah" value="<?=$_COOKIE['blah']?>">

That way if there is a cookie it will be used :)

stidj

4:19 pm on Aug 6, 2005 (gmt 0)

10+ Year Member



I think I'll go with that route.
I'll check for the existence of the $_POST variable name (as in the variable existing not being NULL) because that would be most up to date, if that does not exist then I will take it from the $_COOKIE

Thanks :)

stidj

6:31 pm on Aug 6, 2005 (gmt 0)

10+ Year Member



After playing around some more this worked:

eval('$value='.$check_variable.';');

Thanks again :)