September 1, 201115 yr I want to have it so the results of a form, sent by PHP, are then displayed on a page seperate to the page used to send the form data. I have my PHP to send the data. I have my page to display the data. I now want to pass the variables from the PHP file that sends the form variables, on success of sending the email, to the page that displays the data. The page that displays the data does it by using ECHO. So my theory is, I have a second, hidden form on the sendmail PHP file. When the email successfully sends, it populates the values of the form fields using ECHO, e.g. value="<?php echo $_POST["name"]; ?>" Am I on the right track? Edited September 1, 201115 yr by brightonmike
September 2, 201115 yr Author I tried that. But I just got errors. I have no idea really what I'm doing with this. Currently, the php that sends the form redirects the user: if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=http://localhost/wordpress/wp-content/themes/jetbook2012/quoteresult.php\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=http://localhost/wordpress/wp-content/themes/jetbook2012/quotefail.php\">"; } "quoteresult.php" is the page that should display the form data. I'm imagining this is the wrong way to do it. One thing I don't get is, if you're echo'ing the data into another form on the page that sends the email - surely the user will then need to click a submit button? Argh, I'm so confused.
September 2, 201115 yr Don't mix your quotes value="<?php echo $_POST['name']; ?>" With that sort of redirect, POST won't work. Try using SESSION instead: http://www.tizag.com/phpT/phpsessions.php Edited September 2, 201115 yr by Spitfire
September 2, 201115 yr Author Don't mix your quotes value="<?php echo $_POST['name']; ?>" With that sort of redirect, POST won't work. Try using SESSION instead: http://www.tizag.com/phpT/phpsessions.php Should I scrap my whole form and re-write it? I've read up on Sessions but I read that they aren't very secure or something...?
September 2, 201115 yr Author How does this look? I start the session on the page with the form. <?php session_start(); ?> This is the new send file. I'm retrieving the variables to send them through email. But I'm also storing them again, so the page that displays next can then display them. <?php session_start(); $EmailFrom = "michael.gunner09@gmail.com"; $EmailTo = "michael.gunner09@gmail.com"; $Subject = "Contact Form Submission"; $_SESSION['name'] = $_POST['name']; $_SESSION['email'] = $_POST['email']; $_SESSION['number'] = $_POST['number']; $_SESSION['FlightType'] = $_POST['FlightType']; $_SESSION['from'] = $_POST['from']; $_SESSION['to'] = $_POST['to']; $_SESSION['via'] = $_POST['via']; $_SESSION['depdate'] = $_POST['depdate']; $_SESSION['dephour'] = $_POST['dephour']; $_SESSION['depmin'] = $_POST['depmin']; $_SESSION['retdate'] = $_POST['retdate']; $_SESSION['rethour'] = $_POST['rethour']; $_SESSION['retmin'] = $_POST['retmin']; $_SESSION['name'] = $name; $_SESSION['email'] = $email; $_SESSION['number'] = $number; $_SESSION['FlightType'] = $FlightType; $_SESSION['from'] = $from; $_SESSION['to'] = $to; $_SESSION['via'] = $via; $_SESSION['depdate'] = $depdate; $_SESSION['dephour'] = $dephour; $_SESSION['depmin'] = $depmin; $_SESSION['retdate'] = $retdate; $_SESSION['rethour'] = $rethour; $_SESSION['retmin'] = $retmin; // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $name; $Body .= "\n"; $Body .= "Email: "; $Body .= $email; $Body .= "\n"; $Body .= "Number: "; $Body .= $number; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=http://localhost/wordpress/wp-content/themes/jetbook2012/quoteresult.php\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=http://localhost/wordpress/wp-content/themes/jetbook2012/quotefail.php\">"; } ?> Am I on the right track here?
September 2, 201115 yr Yup, that's the right idea. Remember to use session_start() on the other page as well so you can access the Session variables. You could use: foreach ($_POST as $name => $value){ $_SESSION[$name] = $value; } To convert all those POST variables into SESSION and save a bit of code. Also, as there's no HTML before the redirect I'd use header() redirect (ie: http://php.net/manual/en/function.header.php) instead of meta tags.
September 2, 201115 yr How does this look? I start the session on the page with the form. <?php session_start(); ?> This is the new send file. I'm retrieving the variables to send them through email. But I'm also storing them again, so the page that displays next can then display them. <?php session_start(); $EmailFrom = "michael.gunner09@gmail.com"; $EmailTo = "michael.gunner09@gmail.com"; $Subject = "Contact Form Submission"; $_SESSION['name'] = $_POST['name']; $_SESSION['email'] = $_POST['email']; $_SESSION['number'] = $_POST['number']; $_SESSION['FlightType'] = $_POST['FlightType']; $_SESSION['from'] = $_POST['from']; $_SESSION['to'] = $_POST['to']; $_SESSION['via'] = $_POST['via']; $_SESSION['depdate'] = $_POST['depdate']; $_SESSION['dephour'] = $_POST['dephour']; $_SESSION['depmin'] = $_POST['depmin']; $_SESSION['retdate'] = $_POST['retdate']; $_SESSION['rethour'] = $_POST['rethour']; $_SESSION['retmin'] = $_POST['retmin']; $_SESSION['name'] = $name; $_SESSION['email'] = $email; $_SESSION['number'] = $number; $_SESSION['FlightType'] = $FlightType; $_SESSION['from'] = $from; $_SESSION['to'] = $to; $_SESSION['via'] = $via; $_SESSION['depdate'] = $depdate; $_SESSION['dephour'] = $dephour; $_SESSION['depmin'] = $depmin; $_SESSION['retdate'] = $retdate; $_SESSION['rethour'] = $rethour; $_SESSION['retmin'] = $retmin; // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $name; $Body .= "\n"; $Body .= "Email: "; $Body .= $email; $Body .= "\n"; $Body .= "Number: "; $Body .= $number; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=http://localhost/wordpress/wp-content/themes/jetbook2012/quoteresult.php\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=http://localhost/wordpress/wp-content/themes/jetbook2012/quotefail.php\">"; } ?> Am I on the right track here? um theres no need for sessions at all in this case , and certainly not that redirect at the end, plus ur doing no filtering on anything so expect, alot of form spam, i'd just use a prebuilt form and add the extra fields as needed, you can display the post values directly on the success page theres no need to put them in sessions post values will carry over them self, non the less sessions are not secure to handle form input like that, ps. you can direct using header('Location:successpage'); exit; Edited September 2, 201115 yr by webdesigner93
September 2, 201115 yr Author um theres no need for sessions at all in this case , and certainly not that redirect at the end, plus ur doing no filtering on anything so expect, alot of form spam, i'd just use a prebuilt form and add the extra fields as needed, you can display the post values directly on the success page theres no need to put them in sessions post values will carry over them self, non the less sessions are not secure to handle form input like that, ps. you can direct using header('Location:successpage'); exit; I'm confused. I tried it without sessions and it didn't work. The data is being passed from a form, then onto a sendmail.php, then being displayed on a third page. I don't know how you could do that without sessions? I can't use a pre-built form btw, this is a custom form, and kind of has to be. Anyway I wanna learn this stuff instead of always using existing things and hacking them around
September 2, 201115 yr Why does it need to be passed on to a third page? You could just have 2 files: 1) The form page. 2) The php page you POST the data to. And include any content you want to be displayed there.. Here's an example: Form page <html> <body> <form action="process.php" method="post"> Name: <input type="text" name="name" /> Email: <input type="text" name="email" /> <input type="submit" /> </form> </body> </html> PHP page - "process.php" <html> <body> <?php $name = POST['name']; $email = POST['email']; //display all other content, including POSTed information. echo 'Hey my name is' . $name . ', you can contact me at' . $email; //or just include a whole file with information include(somemorecontent.php); ?> </body> </html> Hope that helped..
September 2, 201115 yr I'm confused. I tried it without sessions and it didn't work. The data is being passed from a form, then onto a sendmail.php, then being displayed on a third page. I don't know how you could do that without sessions? I can't use a pre-built form btw, this is a custom form, and kind of has to be. Anyway I wanna learn this stuff instead of always using existing things and hacking them around um yea it cant be passed to a third page just the process page as mentioned above why do u need a 3rd page?
September 3, 201115 yr Author The reason is I've already built the third page. It has a lot of other stuff on it, such as a bespoke Google maps setup, that works with information from the form. But it looks like this: include(somemorecontent.php); Could just pull that in? I can't do anything/try anything until I'm back at work Monday but I think what I will do is just have it so that the information IS displayed on the third page, but the third page is pulled in with an include - on success of sending the email. If that doesn't work then I can still keep the third page but have all the code to display the form data directly in the sendmail page. Thanks guys for all your help. I know this is probably all dead obvious to you but was quite tricky for me as I'm more of a designer! Thanks Edited September 3, 201115 yr by brightonmike
September 3, 201115 yr Why not use a database and store the information from the form there if the email was successful, you can then use that information on any page you wish
September 3, 201115 yr include(somemorecontent.php); Could just pull that in? I can't do anything/try anything until I'm back at work Monday but I think what I will do is just have it so that the information IS displayed on the third page, but the third page is pulled in with an include - on success of sending the email. Yes that's exactly the idea! All big PHP files have several files with several functions and content. Take these forums for example, it has several hundreds of files doing different functions yet, you only ever see one the single one 'index.php' file. As all the other scripts are included/integrated into it. include() is especially useful if you want to use that content on several pages, which means you can just edit that one file and it will be edited everywhere you include it in. Hope that helped you. EDIT: Also you can just do this: if ($success){ include("somemorecontent.php"); } else{ print "There's an error here.."; } Edited September 3, 201115 yr by Samus
September 5, 201115 yr Author Yes that's exactly the idea! All big PHP files have several files with several functions and content. Take these forums for example, it has several hundreds of files doing different functions yet, you only ever see one the single one 'index.php' file. As all the other scripts are included/integrated into it. include() is especially useful if you want to use that content on several pages, which means you can just edit that one file and it will be edited everywhere you include it in. Hope that helped you. EDIT: Also you can just do this: if ($success){ include("somemorecontent.php"); } else{ print "There's an error here.."; } You &%$£!!! LEGEND. It works a dream. Thank you so much mate. Please by all means let me know if you ever need help with anything, I have a favour to return.
September 5, 201115 yr You &%$£!!! LEGEND. It works a dream. Thank you so much mate. Please by all means let me know if you ever need help with anything, I have a favour to return. Anytime mate.
Create an account or sign in to comment