View Full Version : Bring a form submission to the next page, how?
killrwhale 04-08-2010, 07:17 PM Hello,
I am wanting to have a standard form submission on a page, that then takes the inputed info and brings it to the next page after they submit it. This seems like a basic question, but I don't really understand how form submissions carry over to the next page.
Please help.
Thank You
canishosting 04-08-2010, 11:36 PM Do you know any programming by chance? PHP or Perl or ASP or something?
This isn't real difficult actually. You just need to capture the POST or GET variables (whichever is being sent) and have them populate the form values on the next page.
meijin 04-09-2010, 01:45 AM This is example form:
<form action="WHERE DO YOU WANT TO REDIRECT AFTER SUBMIT" method="METHOD OF THE FORM">
<input name="NAME OF FIELD" value="VALUE OF FIELD" type="" />
<input type="submit" value="OUR SUBMIT BUTTON" />
</form>
And now you have to specify:
action - for ex. secondpage.php. After submit user will be moved to the secondpage.php
method - POST or GET - if you use get - after submit you have all variables in address bar : secondpage.php?field1=value&field2=value.
In your PHP file (you may also use different ways but I have understood that you have never used forms so php is the best for the beginning) you can refer to the variables like that.
It depends on what method have you used:
// for POST you must use $_POST:
echo $_POST['field1'];
echo $_POST['field2'];
// for GET you must use $_GET:
echo $_GET['field1'];
echo $_GET['field2'];
// you may also use $_REQUEST which contains both of them:
echo $_REQUEST['field1'];
echo $_REQUEST['field2'];
mattle 04-09-2010, 08:25 AM Hello,
I am wanting to have a standard form submission on a page, that then takes the inputed info and brings it to the next page after they submit it. This seems like a basic question, but I don't really understand how form submissions carry over to the next page.
Please help.
Thank You
They're sent as part of the request header, either in the url (GET) or separately (POST). See also: http://www.cs.tut.fi/~jkorpela/forms/methods.html
Different programming environment will have different routines to access this data, but you will need to use some kind of server side processing technology (like PHP, ASP, etc.)
tim2718281 04-09-2010, 08:50 AM I think the OP may want the PHP header function:
formtest.php
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' />
<title>Form test, shows PHP opening a web page with parameter specified in form</title>
</head>
<body topmargin="0">
<form action="formtestex.php" method="POST">
<input name="field1" value="99" type="" />
<input type="submit" value="submit1" />
</form>
</body>
</html>
And here is formtestex.php:
<?php
/* Formtestex.php */
$field1 = $_REQUEST['field1'] ;
if (!empty($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS'])) {
$uri = 'https://';
} else {
$uri = 'http://';
}
sleep(3);
$uri .= $_SERVER['HTTP_HOST'];
header('Location: '.$uri.'/formtest.php?field1=' . $field1);
exit;
?>
bobbravo2 04-09-2010, 10:27 AM Just to give a little more summary on the OP. To have a form that displays the information submitted on the first page (say, for confirmation of the information) you can use php, and even one page. Here is how I'd structure the PHP page:
<?php
if ($_POST) {
//logic to pass data through on POST of form info
//You could have a "Confirm" named button that appears once the info has been set, and upon re-posting it to this form, have this part of the script incorporate logic to save the info to a MySQL DB, flatfile, or send an email.
}?>
<html>
<head>
<title>Test Form</title>
</head>
<body>
<h1>Test Form</h1>
<form method="post">
<input name="first_name" type="text" size="40" value="
<?php if (isset($_POST['first_name'])) {
echo $_POST['first_name']) //this will echo out the POSTed value of the form if it has been set
} else {
echo 'Please enter your first name' } //this is the default value
?>" />
<input name="Submit" type="submit" />
</form>
</body>
</html>
killrwhale 04-09-2010, 07:28 PM I think the OP may want the PHP header function:
formtest.php
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' />
<title>Form test, shows PHP opening a web page with parameter specified in form</title>
</head>
<body topmargin="0">
<form action="formtestex.php" method="POST">
<input name="field1" value="99" type="" />
<input type="submit" value="submit1" />
</form>
</body>
</html>
And here is formtestex.php:
<?php
/* Formtestex.php */
$field1 = $_REQUEST['field1'] ;
if (!empty($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS'])) {
$uri = 'https://';
} else {
$uri = 'http://';
}
sleep(3);
$uri .= $_SERVER['HTTP_HOST'];
header('Location: '.$uri.'/formtest.php?field1=' . $field1);
exit;
?>
Hey, thank you for this! I see that it adds the submission to the title. But how do I go to a page after submission that displays the submission on the page?
tim2718281 04-10-2010, 04:39 AM Hey, thank you for this! I see that it adds the submission to the title. But how do I go to a page after submission that displays the submission on the page?
It included the form submission as a parameter.
The target page needs to have code that uses the parameter.
For example, formtest.php:
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' />
<title>Form test, shows PHP opening a web page with parameter specified in form</title>
</head>
<body topmargin="0">
<?php
$field1 = 'default value';
if (isset($_GET['field1']) && $_GET['field1'] != "") {
$field1 = $_GET['field1'];
}
echo 'field1 was ' . $field1 . '<br />';
?>
<form action="formtestex.php" method="POST">
<input name="field1" value="99" type="" />
<input type="submit" value="submit1" />
</form>
</body>
</html>
killrwhale 05-27-2010, 02:18 PM It included the form submission as a parameter.
The target page needs to have code that uses the parameter.
For example, formtest.php:
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' />
<title>Form test, shows PHP opening a web page with parameter specified in form</title>
</head>
<body topmargin="0">
<?php
$field1 = 'default value';
if (isset($_GET['field1']) && $_GET['field1'] != "") {
$field1 = $_GET['field1'];
}
echo 'field1 was ' . $field1 . '<br />';
?>
<form action="formtestex.php" method="POST">
<input name="field1" value="99" type="" />
<input type="submit" value="submit1" />
</form>
</body>
</html>
That worked for me! Thank You! But sometimes when I put something in the form, I get this error:
Service Temporarily Unavailable
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
TheSimpleHost-Nathan 05-27-2010, 02:46 PM I personally would have used sessions.
killrwhale 05-27-2010, 03:48 PM I personally would have used sessions.
How do you do that?
RincewindWizard 05-31-2010, 05:37 AM I personally would have used sessions.
Why would you do that? In this very simple example it's unnecessary and the above approach has the added benefit of working without cookies.
|