dink87522 Posted August 8, 2009 Share Posted August 8, 2009 A user fills out a couple of text fields and the form is submitted and I use $_POST to get those answer's. What I want to do is to send a variable (i.e. $dummy) from that form page to the page which will process the form (both are php). How would I go about this? I tried using a hidden text field although this did not work. Quote Link to comment https://forums.phpfreaks.com/topic/169373-solved-how-to-send-a-variable-when-sending-a-form/ Share on other sites More sharing options...
wildteen88 Posted August 8, 2009 Share Posted August 8, 2009 Post here the code that didn't work. Quote Link to comment https://forums.phpfreaks.com/topic/169373-solved-how-to-send-a-variable-when-sending-a-form/#findComment-893697 Share on other sites More sharing options...
dink87522 Posted August 8, 2009 Author Share Posted August 8, 2009 <input type="hidden" name="result" value="$rnd"/> Quote Link to comment https://forums.phpfreaks.com/topic/169373-solved-how-to-send-a-variable-when-sending-a-form/#findComment-893699 Share on other sites More sharing options...
grunshaw Posted August 8, 2009 Share Posted August 8, 2009 A hidden field should work fine, but it would help to see your code so we can see how you have defined your variable, but generally this is how you would do it. I dont know what your variable does so i'll assume it holds a static value like an email address. <? $email="[email protected]"; ?> <form action="nextpage.php" method="post" name="form1"> Your Name: <input type="text" name="name" value="" /><br /> Your Email: <input type="text" name="useremail" value="" /><br /> Comments: <textarea name="comments"></textarea> <input type="hidden" name="email" value="<? echo $email ?"><br /> <input type="submit" name="send" value="Send"> <input type="reset" name="reset" value="Reset"> </form? Then to capture it on the nextpage.php <? $name=$_POST['name']; $useremail=$_POST['useremail']; $comments=$_POST['comments']; // This is your hidden field $email=$_POST['email']; ?> That should do you! Quote Link to comment https://forums.phpfreaks.com/topic/169373-solved-how-to-send-a-variable-when-sending-a-form/#findComment-893702 Share on other sites More sharing options...
dink87522 Posted August 8, 2009 Author Share Posted August 8, 2009 Thanks Grunshaw, that worked exactly like I wanted. I wasn't using PHP to echo the variable. Quote Link to comment https://forums.phpfreaks.com/topic/169373-solved-how-to-send-a-variable-when-sending-a-form/#findComment-893705 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.