Megan Posted July 29, 2014 Share Posted July 29, 2014 I have created the below code for my website www.pearsonkoutcherlaw.com: <?php if (isset($_POST['formSubmit'])) { header("location: http://www.pearsonkoutcherlaw.com/abl-form-submit/"); exit; print "<p style=\"font-weight:bold;\">Form has been sent!</p>"; print '<p>Thank you for your submission. </p>'; print "<p>What You Sent</p>"; print "<b>Name:</b><br/>".$name."<br/><br/>"; print "<b>Email:</b><br/>".$email."<br/><br/>"; print "<b>Phone:</b><br/>".$phone."<br/><br/>"; print "<b>Message:</b><br/>".$message."<br/><br/>"; } else { ?>`` So, after submission, the user is redirected to http://www.pearsonkoutcherlaw.com/abl-form-submit/. However, I also want the print functions, "Form has been sent", "Thank you for your submission." to appear on the redirect page? How do I do that? Thanks, Megan Quote Link to comment Share on other sites More sharing options...
ginerjm Posted July 29, 2014 Share Posted July 29, 2014 Move those vars you have made to $_SESSION and then they will be available to your next script, if you start it there. Quote Link to comment Share on other sites More sharing options...
Megan Posted July 29, 2014 Author Share Posted July 29, 2014 Thank you for your reply, but i am very new at this and do not think that I really understand? I replaced, $_POST with $_SESSION and now when I fill out the contact form, instead of redirecting, it just refreshed to the original URL? Could you please explain what you mean by "more those vars" Thank you for your time. Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted July 29, 2014 Share Posted July 29, 2014 Is the header() redirect needed? As an alternative, you could just display the confirmation page and provide a link to the next page (http://www.pearsonkoutcherlaw.com/abl-form-submit/). Quote Link to comment Share on other sites More sharing options...
Megan Posted July 29, 2014 Author Share Posted July 29, 2014 I do not believe that I can do it that way because I created a template page in wordpress. Quote Link to comment Share on other sites More sharing options...
Megan Posted July 29, 2014 Author Share Posted July 29, 2014 I apologize, please ignore my last comment. What I am aiming to do, is have the user submit and then go to this URL (http://www.pearsonko...bl-form-submit/), which will have what that user had written on the contact form on it. Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted July 29, 2014 Share Posted July 29, 2014 Thank you for your reply, but i am very new at this and do not think that I really understand? I replaced, $_POST with $_SESSION and now when I fill out the contact form, instead of redirecting, it just refreshed to the original URL? Could you please explain what you mean by "more those vars" Thank you for your time. If you prefer to stick with using a header() redirect, you could save the form information into SESSION variables as ginerjm suggested. <?php if (isset($_POST['formSubmit'])) { //START A SESSION session_start(); //CREATE SESSION VARIABLES $_SESSION['name'] = $name; //... //REDIRECT VISITOR header("location: http://www.pearsonkoutcherlaw.com/abl-form-submit/"); exit; } ?> Then on the confirmation page, you would just need to open the session again to get the variables. <?php //START A SESSION session_start(); //DISPLAY CONFIRMATION print "<p style=\"font-weight:bold;\">Form has been sent!</p>"; print '<p>Thank you for your submission. </p>'; print "<p>What You Sent</p>"; print "<b>Name:</b><br/>" . htmlspecialchars($_SESSION['name']) ."<br/><br/>"; //... ?> More information about sessions can be found in the manual: http://php.net/manual/en/session.examples.basic.php Quote Link to comment Share on other sites More sharing options...
Megan Posted July 31, 2014 Author Share Posted July 31, 2014 Thank you for the information and the article. It was very helpful. Unfortuately, I have played around with this for a few days and am still getting an error using the code below. Any advise? <?php if (isset($_POST['formSubmit'])) { //START A SESSION session_start(); //CREATE SESSION VARIABLES $_SESSION['name'] = $name; $_SESSION['email'] = $email; $_SESSION['phone'] = $phone; $_SESSION['message'] = $message; // //REDIRECT VISITOR header("location: http://www.pearsonkoutcherlaw.com/abl-form-submit/"); exit; } ?> Thank you. Quote Link to comment Share on other sites More sharing options...
CroNiX Posted July 31, 2014 Share Posted July 31, 2014 What error are you seeing? Normally you'd put session_start(); at the very top of your script, on every page. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted August 1, 2014 Share Posted August 1, 2014 You really need to do some reading to learn a little bit about php and html processing. Your code shows that you have no clue. Your code shows you placing some values into some session vars. Can I ask you where those values are coming from? Do you know? To us, looking at your script sample, those are undefined values. If you php error checking turned on you would be seeing error messages. Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted August 1, 2014 Share Posted August 1, 2014 (edited) As ginerjm suggested, the variables like $name are probably undefined. Since these variables seems to be coming from a form using the POST method, I would imagine this $_SESSION['name'] = $name; Should be this $_SESSION['name'] = $_POST['name']; Note that I recommend taking this one step at a time. It makes debugging easier. Before worrying about the header() redirect and the page which processes the form information, I would make sure the SESSION variables are getting the values they need. Try commenting out the header() function and just output the SESSION variables. If they contain what you need, you can move to the next step. Edited August 1, 2014 by cyberRobot Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted August 1, 2014 Share Posted August 1, 2014 Normally you'd put session_start(); at the very top of your script, on every page. Just to clarify, it only needs to be added to pages which use SESSION variables. While I agree that session_start() should usually be at the top of the script, this case may be an exception. This script appears to have at least two stages. One to show the form and one that's activated after the form is submitted. Assuming that the SESSION variables are only used in the latter stage, the session doesn't need to be opened until the form is submitted. With that said, session_start() needs to be called before outputting anything. More information can be found here: http://php.net/manual/en/function.session-start.php Quote Link to comment 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.