muppet77 Posted May 21, 2016 Share Posted May 21, 2016 (edited) I am trying to send a php variable called $angle to another script called penalty.php along with an already establish variable called $goaly1 in a URL send method but can't get it going. I have the $goaly1 variable working on its own and I've added in the $angle form so it's probably that bit of the script that doesn't gel. Do I need the penalty.php instruction twice for example? Any suggestions would be appreciated. <html> <body> <form method="post" action="penalty.php"> <input type="checkbox" name="angle" value="1">Angle?</input> <?php $angle = $_POST['angle']; ?> <a href='penalty.php? angle=<?php echo $angle ?>& goaly1=<?php echo $goaly1 ?> '> draw it</a> </html> Edited May 21, 2016 by muppet77 Quote Link to comment https://forums.phpfreaks.com/topic/301224-variable-sent-in-form/ Share on other sites More sharing options...
requinix Posted May 21, 2016 Share Posted May 21, 2016 Making the href span multiple lines like that is not a good idea. Could cause problems. Where is $angle supposed to be coming from? Either it's set in this script, or if it comes from POST data then your script doesn't do anything and just keeps that form (and penalty.php gets the value from $_POST). Quote Link to comment https://forums.phpfreaks.com/topic/301224-variable-sent-in-form/#findComment-1533124 Share on other sites More sharing options...
muppet77 Posted May 21, 2016 Author Share Posted May 21, 2016 $angle comes from the checkbox entry. (I'm a novice please be gentle!) Quote Link to comment https://forums.phpfreaks.com/topic/301224-variable-sent-in-form/#findComment-1533125 Share on other sites More sharing options...
requinix Posted May 21, 2016 Share Posted May 21, 2016 Then penalty.php can get the value from $_POST by itself. Like you're doing in whatever that file you posted is. You don't need to do this "send a php variable" stuff. Quote Link to comment https://forums.phpfreaks.com/topic/301224-variable-sent-in-form/#findComment-1533126 Share on other sites More sharing options...
muppet77 Posted May 21, 2016 Author Share Posted May 21, 2016 Thanks. So what would it look like please? Quote Link to comment https://forums.phpfreaks.com/topic/301224-variable-sent-in-form/#findComment-1533127 Share on other sites More sharing options...
muppet77 Posted May 21, 2016 Author Share Posted May 21, 2016 The complication in my head is that $angle has to be a user input but $goaly1 is calculated in the php code above. Both need to be sent to penalty.php Quote Link to comment https://forums.phpfreaks.com/topic/301224-variable-sent-in-form/#findComment-1533128 Share on other sites More sharing options...
Solution Barand Posted May 21, 2016 Solution Share Posted May 21, 2016 (edited) Use a hidden field in the form for the goalie value form.php <?php $goalie = 'someCalculatedValue'; // calculate the goalie value ?> <html> <body> <form method="post" action="penalty.php"> <input type="hidden" name="goalie1" value="<?=$goalie?>"> <!-- store the goalie value in a hidden field --> <input type="checkbox" name="angle" value="1"> <input type="submit" name="btnSubmit" value="Submit"> </form> </body> </html> penalty.php <?php $goalie = $_POST['goalie']; $angle = $_POST['angle'] ... ?> Edited May 21, 2016 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/301224-variable-sent-in-form/#findComment-1533129 Share on other sites More sharing options...
muppet77 Posted May 21, 2016 Author Share Posted May 21, 2016 (edited) Thanks Barand. Had a quick go but couldn't get it going. Should there be some php in there? Eg rather than your <input type="hidden" name="goalie1" value="<?=$goalie?>"> <!-- store the goalie value in a hidden field --> Should it be <input type="hidden" name="goalie1" value="<?php echo $goalie ?>"> <!-- store the goalie value in a hidden field --> Edited May 21, 2016 by muppet77 Quote Link to comment https://forums.phpfreaks.com/topic/301224-variable-sent-in-form/#findComment-1533131 Share on other sites More sharing options...
muppet77 Posted May 21, 2016 Author Share Posted May 21, 2016 ignore my post above - all sorted. Barand - your solution works perfectly. Thank you Barand and everyone else. Quote Link to comment https://forums.phpfreaks.com/topic/301224-variable-sent-in-form/#findComment-1533132 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.