Pass Specific Infomation On A Button Click

liunx

Guest
Greets!<br /><br />I am interested on how to pass a variable through a button click to a different page. I <u>do not</u> want to do this through the url as shown below<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->http://w.x.com/test.php?var=12<!--c2--></div><!--ec2--><br />I figured I could set a session variable, but not sure how to set one based on the click of a button. The basic idea is I have a grid with (say 5) selections. Each row has a button (or something similar). Any button click goes to the same page (different than the page they are oin, but ending at the same page). And the resulting page will show information based on the button that was clicked.<br /> <br />I probably overexplained for the majority of you, but I wanted to explain it well enough.<br />Thanks!<!--content-->
You could submit a form value using method="post". That way the variable would not show in the url.<br /><br />Something like this:<br /><br /><div class='codetop'>CODE</div><div class='codemain' style='height:200px;white-space:pre;overflow:auto'><form id="var" action="test.php" method="post"><br /><button type="submit" name="var" value="12">Click Here</button><br /></form></div><br /><br />Then in test.php, assign $_POST[var] to whatever variable that you use in your script for the value passed to it.<br /><br />Like:<br /><br /><div class='codetop'>CODE</div><div class='codemain' style='height:200px;white-space:pre;overflow:auto'><?php<br />$input = $_POST['var'];<br />echo $input;<br />?></div><br /><br />It would also be a good idea to write some code to test the contents of the $_POST value to make sure that nothing is being passed to your script that you are not expecting and don't want.<!--content-->
So you are saying to create a FORM for each button visible? Hm. That will probably work! I keep thinking that there is only one form on a page allowe, but that is crazy talk. Thanks! I guess I have been spoiled in ASP. I could write this page in less than 2 minutes in ASP... But PHP is a little easier on the wallet.<br />Thanks again!<!--content-->
You could have one form, with multiple inputs or buttons.<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><form id="var" action="test.php" method="post"><br />This button will pass the value var=12 ?#60;button type="submit" name="var" value="12">Click Here</button><br /><br />This button will pass the value var=14 ?#60;button type="submit" name="var" value="14">Click Here</button><br /><br />This button will pass the value var=16 ?#60;button type="submit" name="var" value="16">Click Here</button><br /><br />This button will pass the value var=18 ?#60;button type="submit" name="var" value="18">Click Here</button><br /><br />This button will pass the value var=20 ?#60;button type="submit" name="var" value="20">Click Here</button><br /></form><!--c2--></div><!--ec2--><!--content-->
Excellent! I can't believe I missed that. Sometimes I stare at things too long and miss the big picture.<br />Thanks a ton!<!--content-->
I'm glad to have helped. Don't feel bad about overlooking the solution -- I just spent half an hour trying to "fix" a program that was working correctly. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/wallbash.gif" style="vertical-align:middle" emoid=":wallbash:" border="0" alt="wallbash.gif" /><!--content-->
 
Back
Top