GrayRyder Posted December 24, 2019 Share Posted December 24, 2019 (edited) How, if possible, can a $var be passed to the forms action php file? I tried everything with no success. Edited December 24, 2019 by cyberRobot Removed email address Quote Link to comment https://forums.phpfreaks.com/topic/309746-variable-passing/ Share on other sites More sharing options...
gw1500se Posted December 24, 2019 Share Posted December 24, 2019 (edited) Try posting your code so we can see what you are talking about. Be sure to use the code icon (<>) and select PHP. Edited December 24, 2019 by gw1500se Quote Link to comment https://forums.phpfreaks.com/topic/309746-variable-passing/#findComment-1572868 Share on other sites More sharing options...
Barand Posted December 24, 2019 Share Posted December 24, 2019 The values in the forms input fields get sent to the action php file, so put it in one. Use a hidden field if you don't want it visible. Quote Link to comment https://forums.phpfreaks.com/topic/309746-variable-passing/#findComment-1572869 Share on other sites More sharing options...
GrayRyder Posted December 24, 2019 Author Share Posted December 24, 2019 Thanks for your reply, here is the php code $SC2 = $input[$rand_keys[0]]; <FORM METHOD="POST" ACTION="SCAction.php/?cmd= set&var1=$SC2"> This passes $SC2 not the contents of $SC2, contents of $SC2 is a 4 char text ex. AAAA Quote Link to comment https://forums.phpfreaks.com/topic/309746-variable-passing/#findComment-1572871 Share on other sites More sharing options...
gw1500se Posted December 24, 2019 Share Posted December 24, 2019 (edited) You are mixing POST and GET. If you want to pass the variables in the URL use GET. You need to output the variables to the form to a field not in the URL. As Barand said it should be in a hidden field if you don't want it displayed on the page. Edited December 24, 2019 by gw1500se Quote Link to comment https://forums.phpfreaks.com/topic/309746-variable-passing/#findComment-1572872 Share on other sites More sharing options...
Barand Posted December 24, 2019 Share Posted December 24, 2019 You also need to output the value into the html from php <FORM METHOD="POST" ACTION="SCAction.php/?cmd= set&var1=<?=$SC2?>"> Quote Link to comment https://forums.phpfreaks.com/topic/309746-variable-passing/#findComment-1572873 Share on other sites More sharing options...
GrayRyder Posted December 24, 2019 Author Share Posted December 24, 2019 After further investigation I don’t need to invoke an action.php file. I think, the comparison can be performed in sceureEmail form used by the user. It still would nice to know if a variable can be passed to the forms action file. Thank for your help in forming my understanding. Quote Link to comment https://forums.phpfreaks.com/topic/309746-variable-passing/#findComment-1572875 Share on other sites More sharing options...
GrayRyder Posted December 24, 2019 Author Share Posted December 24, 2019 Bad news, my last post work around did not work. Let me explain what going on. The user runs securteEmail.php which is a form that sends an email with a random 4 digit code to the users email. The user reads his email and inserts the code sent to his email in the secureEmail.php form, which invokes the action file SCAction.php. The code in the form is successfully sent and read by SCAction.php. Tthe problem, the original code has to be compared to the email code. There for has to be sent to SCAction.php. The email code entered in the form is read from the form by SCaction.php. I need the action code to fetch the users email code that is entered. **** The secureEmail.php code: **** <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Seurity Email Service</title></head> <body> <?php $SC2 = $input[$rand_keys[0]]; echo "SC code sent = ", $SC2, "<br>"; echo "After the SC code is sent to the Email, we are at the Form <br>"; ?> <FORM METHOD="POST" ACTION="SCAction.php/?cmd= set&var1=$SC2"> <H2>Security Code Service</H2> <p>Enter the Security Code from the recipient's Email & Submit </p> <?php $Scode = substr("$Scode", 0, -4); ?> <INPUT NAME="Scode", value = <?php echo (""); ?> > <!-- <input type="submit" /> --> <?php $Scode = $_POST['Scode']; Echo "Scode = $Scode <br>"; echo "<br>Security code (SC = $SC)"; echo " sent to ", $to_address, "<br>"; ?> </FORM> </body> </html> ****The SCAction.php code:**** <?php if(isset($_GET['$SC'])){ $SC=stripslashes($_GET['$SC']); } Echo "SC = $SC <br>"; $Scode = $_POST['Scode']; Echo "Scode = $Scode <br>"; if ($SC === $Scode) { echo "Success, this is the Security Code from the Email : {$_POST['Scode']}<br />"; } else { echo "<br>Illegal Security Code from the Email <br>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/309746-variable-passing/#findComment-1572876 Share on other sites More sharing options...
GrayRyder Posted December 24, 2019 Author Share Posted December 24, 2019 You can try it here: https://rotherforth.net/secureEmail/secureEmail.php You can't read the email, but you can enter any 4 digit code. Quote Link to comment https://forums.phpfreaks.com/topic/309746-variable-passing/#findComment-1572877 Share on other sites More sharing options...
cyberRobot Posted December 24, 2019 Share Posted December 24, 2019 12 minutes ago, GrayRyder said: There for has to be sent to SCAction.php. Did you see Barand's response about PHP variables needing to be outputted in PHP? Try changing this <FORM METHOD="POST" ACTION="SCAction.php/?cmd= set&var1=$SC2"> To this <FORM METHOD="POST" ACTION="SCAction.php/?cmd= set&var1=<?=$SC2?>"> Note the $SC2 variable at the end. Quote Link to comment https://forums.phpfreaks.com/topic/309746-variable-passing/#findComment-1572878 Share on other sites More sharing options...
cyberRobot Posted December 24, 2019 Share Posted December 24, 2019 Also note that you are naming the variable "var1". In SCAction.php, it looks like you are expecting a variable named "SC" here: $SC=stripslashes($_GET['$SC']); Quote Link to comment https://forums.phpfreaks.com/topic/309746-variable-passing/#findComment-1572879 Share on other sites More sharing options...
ginerjm Posted December 24, 2019 Share Posted December 24, 2019 (edited) Ok - you send the user a form with a value in it. Is there really a form involved there? Sounds like you the user simply runs a script to get the code emailed to them, although I don't know how he provides the email address. Is that in this first form? Ok - the user gets an email with a code. is there already a new form on screen for him to switch back to from his email client and type in the just-received code? If so then he simply submits that 2nd form and your server has everything it needs. Either with a hidden field in that second form, or better yet, saved in the session by the first script that created the code. Does that make sense to you? Edited December 24, 2019 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/309746-variable-passing/#findComment-1572880 Share on other sites More sharing options...
GrayRyder Posted December 24, 2019 Author Share Posted December 24, 2019 Many thanks, CyberRobot that fix my problem. Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/309746-variable-passing/#findComment-1572881 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.