Page 1 of 1

Posting Values to Page Quetion

Posted: Wed Apr 28, 2010 2:18 pm
by soma56
In a nutshell I get some data from a user:

PAGE1

Code: Select all

   
<form name="form" method="post" action="proces-this.php">
 <table>
            <tr>
        <td>Name:</td>
        <td><input name="name" type="text" id="name" /></td>
      </tr>
    </table>
  </form>
Then I grab the data

PAGE2

Code: Select all

$name = trim($_POST["name"]);
Then I redirect the user based on the value:

Still PAGE2

Code: Select all

if ($name=="")   
<!--ADD SOME CODE HERE THAT WILL ALLOW ME TO TAKE THE $name VALUE TO EITHER URL BELOW-->
{    
   echo '<META HTTP-EQUIV="Refresh" Content="1; URL=success.php" >';      
}    
else    
{    
   echo '<META HTTP-EQUIV="Refresh" Content="1; URL=no-go.php">';
      
}  
This isn't to redirect users if the name field is blank but for simplicities sake I've posted a very brief version here. The question is how do I grab the data from page 1 and place it on page 3 with the redirect that I have set-up on page 2?

Re: Posting Values to Page Quetion

Posted: Wed Apr 28, 2010 3:15 pm
by social_experiment
What about the following :
Page 1
Form, lets say with a text field.

Code: Select all

<form method="process-this.php" action="post">
<input type="text" name="tField" />
<input type="submit" value="Go" name="btn" />
</form>
Page 2
The process page.

Code: Select all

<?php if (isset($_POST['btn'])) {
 if (isset($_POST['tField'])) {
  $val = clean_up_value($_POST['tField']);
  header("location: Page_3.php?id=$val");
 }
 else {
  echo 'Empty field';
 }
}?>
Page 3

Code: Select all

<?php if (isset($_GET['id'])) {
 $id = clean_up_value($_GET['id']));
 //use as you wish
} ?>
?

Re: Posting Values to Page Quetion

Posted: Wed Apr 28, 2010 4:22 pm
by soma56
Thank you for the response. I tried a few variations and it didn't work. This is what I have:

Page 1
Someone submits their info

Code: Select all

<form  method="process-this.php"  action="post">
<tr><td>Name:</td></tr><input type="text" name="name" />
<tr><td>Email:</td></tr><input type="text" name="email" />
<tr><td>Phone Number (Optional):</td></tr><input type="text" name="phone" />
<input type="submit" value="Go" name="btn" />
</form>
Page 2
The information goes to one of two pages depending on whether or not the 'phone' field is blank. Regardless, the 'name' and 'email' fields must be forwarded to PAGE 3

Code: Select all

<?php 
 if ($phone=="")  
	if (isset($_POST['btn'])) {
 if (isset($_POST['name'])) {
  $val = clean_up_value($_POST['name']);
  header("location: Page_3.php?id=$val");
 }
 else {
  echo '<META HTTP-EQUIV="Refresh" Content="1; URL=page-with-phone-number.php">';
 }
}?>
That being said, to grab and forward more fields from PAGE 1 would I do something like this, correct?

Code: Select all

<?php 
 if (isset($_POST['name'])) {
$val = clean_up_value($_POST['name']);
 if (isset($_POST['email'])) {
$val2 = clean_up_value($_POST['email]);
 if (isset($_POST['phone'])) {
$val3 = clean_up_value($_POST['phone]);
}?>
And then add it like this to my redirect? Am I on the right track?

Code: Select all

  header("location: Page_3.php?id=$val$val2$val3");
I'll put it in a logical way:

> Person submits Name, Email & Phone Number information.
> Where the person submits only their name and email both the name and email get forwarded to page 'X' with the user being redirected to that page respectively.
> Where the person submits all three fields they we'll get forwarded to page 'Y' with the user being redirected to that page respectively.

Re: Posting Values to Page Quetion

Posted: Thu Apr 29, 2010 6:47 am
by social_experiment
soma56 wrote:And then add it like this to my redirect? Am I on the right track?
Almost, your url should look like this :

Code: Select all

<?php header("location: Page_3.php?id=$val&otherVal=$val2&yetAnotherval=$val3"); ?>
soma56 wrote:> Person submits Name, Email & Phone Number information.
> Where the person submits only their name and email both the name and email get
forwarded to page 'X' with the user being redirected to that page respectively.
> Where the person submits all three fields they we'll get forwarded to page 'Y' with the user

Code: Select all

<?php   
 if (isset($_POST['btn'])) {  
  if ($_POST['name'] != '' && $_POST['email'] != '' && 
  $_POST['phone'] != '') {
  	$name = $_POST['name'];
	$email = $_POST['email'];
	$phone = $_POST['phone'];	
	header("location: page_y.php?name=$name&email=$email&phone=$phone");
	exit();
  }
  
  if ($_POST['name'] != '' && $_POST['email'] != '') {
   $name = $_POST['name'];
   $email = $_POST['email'];
   header("location: page_x.php?name=$name&email=$email");
   exit();
  }  
 }
?>
This is the code, it works like your example. It requires some additional checks and security.

Hope it helps.