Hello,
ok, the first script is the POST form. The second script sets up the $_POST values for use. Then, the user has the option to reload the script directly without going back to the form (basically the first script gets user input for a map, and the second script displays the map and allows the user to zoom in or out of the map). But what happens, is that the $_POST values are no longer set, and so of course the script crashes. Do _$POST values only work when they come directly from a POST form? I thought they were globals?
I did try a workaround, by making a hidden form value $from_form, and then after checking to see it false, load the variables from $_SESSIONs, but this seems kinda klunky.
Thanks,
Kilolima
$_POST forgets value when script recalled with <a href
Moderator: General Moderators
- daven
- Forum Contributor
- Posts: 332
- Joined: Tue Dec 17, 2002 1:29 pm
- Location: Gaithersburg, MD
- Contact:
$_POST is a superglobal, but the individual variables (ex: $_POST['myvar']) only exist when they come from a POST form. So when you recall the page using a hyperlink, the variables go away.
A workaround is to create a post form with a submit button and hidden variables instead of a link.
A workaround is to create a post form with a submit button and hidden variables instead of a link.
Code: Select all
<a href="<?=$_SERVERї'PHP_SELF']?>">Your current way of doing this</a>
<form action="<?=$_SERVERї'PHP_SELF']?>" method="post">
<input type="hidden" name="myvar1" value="the value you get from the previous form">
<input type="Submit" value="Click this instead of a link">
</form>Daven,
Thanks, that clears that up about $_GLOBAL...
I would prefer not to replace my <a href links with forms, mostly just because form buttons are so ugly (yes, I know they can be replaced by an image, but how well do the various browsers support this?). Is there no way to have global_vars off and still be able to keep the simple functionality of <a href=self.php?myvar=myvalue>?
I tried:
but this doesn't seem to work. neither does:
Actually, I realize that <a href links are critical to my web application becuase it is using a dynamic image map built via php. Can it be done or do I need to turn global_vars back on (and mabye go to https)?
thanks
kilolima
Thanks, that clears that up about $_GLOBAL...
I would prefer not to replace my <a href links with forms, mostly just because form buttons are so ugly (yes, I know they can be replaced by an image, but how well do the various browsers support this?). Is there no way to have global_vars off and still be able to keep the simple functionality of <a href=self.php?myvar=myvalue>?
I tried:
Code: Select all
echo "<a href=self.php?$_SESSIONїmyvar]=myvalue> clickme </a> ";Code: Select all
<a href=list.php?<? echo "$_SESSIONїmyvar]";?>=myintvalue> clickme</a>thanks
kilolima
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
hey hob_goblin,
Thanks for the javascript tip! Although I usually try to avoid js at all costs, I think this may be a time when it's use is unavoidable. Anyway, this seems to work to allow multiple <a href to each submit different values using the $_POST global vars:
(first this script calls a include with session_start())
This should solve alot of issues and open the way to get around the no global_vars restrictions. Thanks!
kilolima
p.s. just in case, does anybody have a way to do this without using javascript?
Thanks for the javascript tip! Although I usually try to avoid js at all costs, I think this may be a time when it's use is unavoidable. Anyway, this seems to work to allow multiple <a href to each submit different values using the $_POST global vars:
(first this script calls a include with session_start())
Code: Select all
<form method = post name = form2 action = test2.php>
<input type=hidden name=one value=0>
<a href="#" onclick="javascript:document.form2.one.value=10;javascript:document.form2.submit();">Link1</a>
<a href="#" onclick="javascript:document.form2.one.value=20;javascript:document.form2.submit();">Link2 </a>
<a href="#" onclick="javascript:document.form2.one.value=30;javascript:document.form2.submit();">Link3</a>kilolima
p.s. just in case, does anybody have a way to do this without using javascript?
-
superwormy
- Forum Commoner
- Posts: 67
- Joined: Fri Oct 04, 2002 9:25 am
- Location: CT