Jump to content

Contact Form - POST/Sent , then reuse variables


artintc

Recommended Posts

Hello,

I need to do the following:

 

I have 2 forms on two different pages:

Form 1: Name, Email, Phone

Form 2: Name, Email, Phone, Address, etc.

 

1. User fills out Form 1, presses submit

2. Form 1 gets processed and I receive an email with the visitors Name, Email, Phone

3. After the Form has been processed I need to redirect the visitor to a new page (Form 2)

4. When Form 2 loads, fill in the form with the posted variables (Name, Email, Phone) from the previous process

 

Here is my code:

 

Form 1

<!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>
</head>
<body>
<form method="post" action="process_form.php">
<input type="text" name="name" />
<input type="text" name="email" />
<input type="text" name="phone" />
<input type="submit" name="submit" value="submit" />
</form>
</div>
</body>
</html>

 

process_form.php

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];

$to = 'email@provider.com';
$subject = "Contact Form";

$message = 
"Contact Information\r\n"
."$name\r\n"
."$email\r\n"
."$phone\r\n\";

$headers = "From: $email\r\n";

mail($to, $subject, $message, $headers);

// Redirect
header("Location: http://www.domain.com/form2/");
?>

 

Form 2

<!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>
</head>
<body>
<form method="post" action="process_form_2.php">
<input type="text" name="name" />
<input type="text" name="email" />
<input type="text" name="phone" />
<input type="text" name="address" />
<input type="text" name="city" />
<input type="text" name="state" />
.
.
.
<input type="submit" name="submit" value="submit" />
</form>
</div>
</body>
</html>

 

The form does get processed and I do get an email with the visitor's info. But I'm not able to pass on the variables from From1 to Form2.

 

Thank you in advance.

 

Link to comment
Share on other sites

Inside your header redirect link:

 

header("Location: http://www.domain.com/form2/");

 

Change it to and add any more varaibles you want to collect to the address.....like this:

 

header("Location: http://www.domain.com/form2/?&name=<?php echo $name; ?>&email=<?php echo $email; ?>");

 

Then in your form2 use $_GET['name']; etc instead of $_POST. That is if you want those variables displayed in form2.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.