Forum Moderators: coopster

Message Too Old, No Replies

Multi page form & redirect

Can't get form fields to redirected page

         

BreaJR

11:57 pm on Dec 29, 2003 (gmt 0)

10+ Year Member



I'm new to PHP and I'm trying to learn as I go along. I have a multi page form that I carry over hidden fields from one page to the other. I've used the fieldforwarder script, and also tried using sessions. However, when the form is posted, and I redirect to a thank you page, I loose the form field information. I would like to carry parts of that form information to the thank you page, but can't seem to figure out a way to do it. I thought about cookies, but more and more people are not allowing them. What would be the best way to do this? Is there a tutorial somewhere?

Thank you for any help you can provide.

Birdman

1:54 am on Dec 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I can say from experience that multi-page forms are tricky. Quotes are my worst problem, but I think I got that figured.

In your case, I think the problem lies in your redirect to the homepage, as you stated.

When you redirect after form submission, you will need to add the form information to the URL in your redirect. Not with hidden form fields, but by building the 'querystring'.

The redirect in PHP:

header("Location:/thank_you.php?name=$name&whatever=$whatever");

The part starting with "?" is the querystring.

Hope that helps you get on track.

jatar_k

8:20 pm on Dec 30, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld BreaJR,

Sessions are probably a good bet. On your thank you page do you have session_start at the top of it before any output? That may be causing your problem.

Are you getting any errors on the final page that might give us a little more info or is it just blank?

BreaJR

9:53 pm on Dec 30, 2003 (gmt 0)

10+ Year Member



Thank you for your replies. Yes I have this at the top of all of the pages:

<?php
session_start();
session_unregister('email');
session_register('email');
$email = $HTTP_POST_VARS[email];
session_unregister('name');
session_register('name');
$name = $HTTP_POST_VARS[name];
?>

I知 not sure if this is correct, but I was trying to follow a tutorial on sessions and this is what they showed. I can carry not just name and email, but all of the inputs fields with this from page to page in my form. Where I have problems is in the form redirect when you click on send:

<input type="hidden" name="redirect" value="http://mysite.com/thank_you.php">

I loose the data I知 trying to carry over, email and name. I致e tried various ways to send the session in the redirect but so far no luck. I致e been trying to read the manual at php.net but not understanding exactly what I知 reading. I知 sure in time I値l get it, but I知 under a time restraint to get this page done.

Any assistance is very welcome!

Thank you, Jack

bofe

4:17 am on Dec 31, 2003 (gmt 0)

10+ Year Member



BreaJR,

How do you have the form set up?

Are you using seperate files? If you're using just one file, it may be slightly easier-

A possible approach (apologies for messy code)
<?
/* form.php */
/* multiple forms in one php file */
if ($_REQUEST['page'] == "page1" ヲヲ!isSet($_REQUEST['page']))
{
?>
<form method="post" action="<? echo($_SERVER['PHP_SELF'] . "page=page2");?>">
Name: <input type="text" name="name" /><br />
E-mail: <input type="text" name="email" /><br />
<input type="submit" value="Submit" /></form>
<?
}

else if ($_REQUEST['page'] == "page2")
{
$email = $_POST['email'];
$name = $_POST['name'];
?><! -- form for page 2 , set it to post to page 3--><?
}

else if ($_REQUEST['page'] == "page3")
{
?> Thank you for filling out the form <? /* php to add $name, $email, and any other fields to DB */
}
?>