Reputation: 381
I have a php page with a form named "BuyForm" and a separate submit button.. like this
<form id="BuyForm" name="BuyForm" method="post" action="purchase.php" enctype="multipart/form-data">
// form goes here
//example of one field
<div class="wrapper"> Your Name:
<input type="text" class="input" name="txtUserName" value="<?php if(isset($user_name)){echo $user_name;} ?>" <?php if(isset($flag) && $flag == 1){echo "error";}?> >
</div>
// more form options
This form is on this page "purchase.php". The reason of action="purchase.php" i.e. redirecting this form back to this page is that because all validation is in this page only.
Now there is a problem im stuck with and seek opinions..
I want to transfer these form values (for example name="txtUserName") to another page and I know i can directly do it via action="otherpage.php" and recieving there via php. But this could not be possible as i have to move all my current validations to that page (otherpage.php) and if anything is wrong then i have to redirect back to this form page (purchase.php) this will be waste of time and bandwidth and not a good coding.. What else could be done in this case? i.e. how can i send values from this page to that page?
in regards to Q-1 above how can i receive values on that page?
Thanks in anticipation..
Upvotes: 0
Views: 562
Reputation: 7104
Save your $_POST values into array and send via header location.
My example:
$values = $_POST;
header('Location: other_page.php?'.http_build_query($values );
Upvotes: 1
Reputation: 3
You can do something like that:
In your purchase.php:
if(!isset($_POST['var_name'])) {
//here the form code
}
else
{
//here's the validation
}
Upvotes: 0
Reputation: 457
What about using session?
session_start();
foreach ($_POST as $key=>$value){
$_SESSION[$key]=$value;
}
With that you can access that value anywhere
Upvotes: 0