You can only use one form, as you've figured out. You can have PHP determine
the action for each button, though..

In a form with two buttons, say names "submit1" and "submit2", only one
variable will be set when the form is submitted, the actual button that was
clicked. So you can use logic like this in PHP.

<?php
if(isset($_REQUEST['submit1']))
{ echo "button 1 was clicked, act accordingly"; }
elseif(isset($_REQUEST['submit2']))
{ echo "button 2 was clicked, act accordingly"; }
else
{ echo "no button clicked, do not act accordingly?"; }

So this would be in "page4.php". $_REQUEST['someVar'] would be available
here.

Now, you want to redirect to "page5.php" if button two is pressed, right,
yet retain the value of $_POST?

if(isset($_REQUEST['submit2']))
{
    $_SESSION['post'] = $_POST;
    header("Location: http://www.yourdomain.com/page5.php";);
}

Now, on "page5.php", to get $_POST back, just do:

$_POST = $_SESSION['post'];

That's assuming you have session_start() on each page and you don't have
anything in $_POST already on "page5.php" that you want to retain.

---John Holmes

PS: Sorry for the top-post, but OExpress sucks. :)


----- Original Message ----- 
From: "Golawala, Moiz M (IndSys, GE Interlogix)" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, September 15, 2003 4:17 PM
Subject: [PHP] multiple FORMS on same page problem.


I am creating a page with 2 buttons. One which will refresh the page and the
other that will go to another page. My problem that I need to put all the
values into $_POST and have access to when any of the 2 buttons are clicked.
If I use the button in 2 seperate form tags I don't have access to all the
values in $_POST. Please look at the code below:

file (page4.php):

<html>

<form action="page4.php" method=post>
<?php echo "this is page 4"; ?>
<input type=text name='someVal' value=''">
<input type='submit' value='page4 Submit'>
</form>
<form action="page5.php" method=post>
<input type='submit' value='page5 Submit'>
</form>
</html>

file(page5.php):

<?php
$val = $_POST['someVal'];
echo $val;
echo "this is page 5";
?>

I would like to see the variable 'someVal' in the $_POST of both "page4
Submit" button and "page5 Submit" button. This code is a simplified version
of the more complecated code where a tonnes of other values are involved.
Any help is appreciated.

Moiz

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to