Forum Moderators: coopster

Message Too Old, No Replies

Form results repeated on next page?

         

Dexie

9:58 am on Apr 27, 2006 (gmt 0)

10+ Year Member



Anyone know how to get the results of a form generated in php to be repeated on the thank-you page so that the visitor can check what they have just inputted please?

Dexie

eelixduppy

2:44 pm on Apr 27, 2006 (gmt 0)



Hello...

Do something like this:


if($_POST['form_submit'])
{
echo "Thank you for entering your data!<br><br>";
echo "Your first name: $_POST['fname']<br>";
echo "Your last name: $_POST['lname']<br>";
}
else {
echo "<form action=$_SERVER['PHP_SELF'] method='post'>\n
First Name<input type='text' name='fname' size=40><br>\n
Last Name <input type='text' name='lname' size=40><br>\n
<input type='hidden' name='submit_form' value=1>\n
<input type='submit' value='Register!'>\n
</form>";
}

hope this helps

eelixduppy

3:13 pm on Apr 27, 2006 (gmt 0)



I'm sorry, i didn't read correctly...

Do something like this:

session_start();

if($_POST['form_submit'])
{
echo "Thank you for entering your data!<br><br>";
echo "Your first name: $_POST['fname']<br>";
echo "Your last name: $_POST['lname']<br><br>";
echo "Is this information correct?<br>";
//links to make it simpler
echo "<a href='form.php?add=0'>NO</a>";
echo "<a href='form.php?add=1'>YES</a>";

$_SESSION[fname] = $_POST[fname];
$_SESSION[lname] = $_POST[lname];

}
else if($_GET[add] == 1) { //Here is obviously a security issue but its for demostration purposes

//code to add info to database but use the session variables
unset($_SESSION[fname]);
unset($_SESSION[lname]);
session_destroy();
}
else {
unset($_SESSION[fname]);
unset($_SESSION[lname]);
session_destroy();
echo "<form action=form.php method='post'>\n
First Name<input type='text' name='fname' size=40><br>\n
Last Name <input type='text' name='lname' size=40><br>\n
<input type='hidden' name='submit_form' value=1>\n
<input type='submit' value='Register!'>\n
</form>";
}

There are some issues with security here but i just wanted to show you. Im really tired so you might have to check the code for errors...then again the whole thing could be an error.

Hope this helps...im going back to sleep

eelix

hope this helps

Dexie

6:31 am on Apr 28, 2006 (gmt 0)

10+ Year Member



Many thanks Eelix, it's appreciated.

A couple of things, I don't have a databse associated with this yet, (it's on my list of to-do's!), so would it be ok to leave that part out?

Also, does this code go on the form page or the thank-you page please?

Any help appreciated.

Dexie.

eelixduppy

12:55 pm on Apr 28, 2006 (gmt 0)



Hello...

Actually as i have it now, its both a form and a thank you page. If you want to split the code into two pages, this is how it could look:

form.html


<form action=thank_you.php method='post'>
First Name<input type='text' name='fname' size=40><br>
Last Name <input type='text' name='lname' size=40><br>
<input type='hidden' name='submit_form' value=1>
<input type='submit' value='Register!'>
</form>

thank_you.php


<?php
session_start();

if($_POST['form_submit'])
{
echo "Thank you for entering your data!<br><br>";
echo "Your first name: $_POST['fname']<br>";
echo "Your last name: $_POST['lname']<br><br>";
echo "Is this information correct?<br>";

//links to make it simpler
echo "<a href='form.php?add=0'>NO</a>";
echo "<a href='form.php?add=1'>YES</a>";

$_SESSION[fname] = $_POST[fname];
$_SESSION[lname] = $_POST[lname];

}
else if($_GET[add] == 1) { //Here is obviously an issue but its for demostration purposes

//Code to use information after it has been verified...

unset($_SESSION[fname]);
unset($_SESSION[lname]);
session_destroy();
}
else {
unset($_SESSION[fname]);
unset($_SESSION[lname]);
session_destroy();

echo "<form action=form.php method='post'>\n
First Name<input type='text' name='fname' size=40><br>\n
Last Name <input type='text' name='lname' size=40><br>\n
<input type='hidden' name='submit_form' value=1>\n
<input type='submit' value='Register!'>\n
</form>";
}
?>

Something like this...Hope this helps

eelix

Dexie

4:17 pm on Apr 28, 2006 (gmt 0)

10+ Year Member



Many thanks Eelix, I haven't got any form actions in the code at the moment, but the code does include:

if($_POST["formsent"] == "formsent")

and

// redirect to the thank you page
header("Location: [website...] address.com/enquiry-thanks");

The helps appreciated.

Dexie.