Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Multiple POST

Featured Replies

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 by brightonmike

  • 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.

  • 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...?

  • 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?

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.

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 by webdesigner93

  • 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 :p

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..

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 :p

um yea it cant be passed to a third page just the process page as mentioned above why do u need a 3rd page?

  • 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 by brightonmike

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

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 by Samus

  • 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. :)

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.