Ask a Question related to PHP Development, Design and Development.
-
Moiz M Golawala #1
[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
Moiz M Golawala Guest
-
Strange problem with Forms authentication: After successfull login, login page is still displayed
Hi there I have a quite strange problem with my ASP.NET-Application. The application has being deployed one year ago and worked fine till last... -
Multiple Forms in one page
Is there any way to have multiple forms in one page without having the forced space between the submit buttons that each form has? In other... -
Multiple forms on one page
I am trying to put together a stripped-down online order form that allows a user to enter quantities ordered for a bunch of products, as well as... -
How to include multiple <forms> on one ASP.NET page
Hi, I need to create an ASPX page that includes both traditional HTML Forms (which are submitted to a third-party site like a travel booking... -
problem with have multiple subjects appear on the web page in multiple lines
Hello, group I have got this problem, hoping someone can help me to figure it out what is wrong. I have some fields in the database:... -
Warren Vail #2
RE: [PHP] multiple FORMS on same page problem.
I don't know of any rule that says you cannot have two submit button in the same form.
Of course, if you need to know which was clicked, you will either need to name them differently or detect their values in your form processing routine. If the button is clicked that should take you to another form simply do a redirect (after processing all $_POST information);
header("Location: new page");
exit; // I always use this because processing continues after header
good luck,
Warren Vail
-----Original Message-----
From: Golawala, Moiz M (IndSys, GE Interlogix)
[mailto:Moiz.Golawala@ge.com]
Sent: Monday, September 15, 2003 1:17 PM
To: [email]php-general@lists.php.net[/email]
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
Warren Vail Guest
-
Cpt John W. Holmes #3
Re: [PHP] multiple FORMS on same page problem.
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)" <Moiz.Golawala@ge.com>
To: <php-general@lists.php.net>
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
Cpt John W. Holmes Guest
-
Chris Shiflett #4
Re: [PHP] multiple FORMS on same page problem.
--- "Golawala, Moiz M (IndSys, GE Interlogix)" <Moiz.Golawala@ge.com> wrote:
....> I am creating a page with 2 buttons.....> <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>Then put someVal in both forms. When you submit a form, only the data in the> I would like to see the variable 'someVal' in the $_POST of both
> "page4 Submit" button and "page5 Submit" button.
form will be sent to the server.
Chris
=====
Become a better Web developer with the HTTP Developer's Handbook
[url]http://httphandbook.org/[/url]
Chris Shiflett Guest
-
Gary Petersen #5
Re: [PHP] multiple FORMS on same page problem.
On Mon, 15 Sep 2003 15:35:50 -0500, Cpt John W. Holmes created an
award-winning crop circle <010901c37bc8$f3bd2200$a629089b@TBHHCCDR>,
which, when translated into English, means this:
I believe that there is a patch for MSOE that fixes> [...]
>
> PS: Sorry for the top-post, but OExpress sucks. :)
>
> [...]
its quoting problem. Google for "quotefix" and/or "sigfix."
Gary Petersen Guest
-
Moiz M Golawala #6
RE: [PHP] multiple FORMS on same page problem.
It is almost working.. I can't figure out why I can get the "someVal" to page5.php.
file: page4.php
<?php
if (isset($_REQUEST['submit1'])){
echo "button 1 was clicked, act accordingly";
echo "this the request values";
echo $_REQUEST['someVal'];
}elseif(isset($_REQUEST['submit2'])){
session_start();
echo "button 2 was clicked, act accordingly";
$_SESSION['post'] = $_POST;
header("Location: http://127.0.0.1/Alarms/page5.php?<?=SID?>");
}else{
echo "NO button clicked, do not act accordingly";
}
?>
<html>
<form action="page4.php" method=post>
<?php echo "this is page 4"; ?>
<input type=text name='someVal' value=''>
<input type='submit' name="submit1" value='page4 Submit'>
</form>
<form action="page4.php" method=post>
<input type='submit' name="submit2" value='page5 Submit'>
</form>
</html>
file: page5.php
<?php
$_POST = $_SESSION['post'];
$val = $_POST['someVal'];
echo $val;
echo "this is page 5";
?>
for some reason I get the error that the header was already sent. I have to send the session Id to the next page the old fashioned way since I have another problem that causes a new session to be created everytime a page is loaded. Do you where the problem is?
Thanx
Moiz
-----Original Message-----
From: CPT John W. Holmes [mailto:holmes072000@charter.net]
Sent: Monday, September 15, 2003 4:36 PM
To: Golawala, Moiz M (IndSys, GE Interlogix); [email]php-general@lists.php.net[/email]
Subject: Re: [PHP] multiple FORMS on same page problem.
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)" <Moiz.Golawala@ge.com>
To: <php-general@lists.php.net>
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
Moiz M Golawala Guest
-
Jan Ruessel #7
RE: [PHP] multiple FORMS on same page problem.
You could also redirect with javascript:
echo "<Script Lang=javascript>";
echo "window.location.href = 'page5.php'";
echo "</script>";
Grtz
Jan
-----Original Message-----
From: John W. Holmes [mailto:holmes072000@charter.net]
Sent: Dienstag, 16. September 2003 18:06
To: Golawala, Moiz M (IndSys, GE Interlogix)
Cc: [email]php-general@lists.php.net[/email]
Subject: Re: [PHP] multiple FORMS on same page problem.
Golawala, Moiz M (IndSys, GE Interlogix) wrote:
header("Location: http://127.0.0.1/Alarms/page5.php?" . SID);> It is almost working.. I can't figure out why I can get the "someVal" to page5.php.
>
> file: page4.php
>
> <?php
>
> if (isset($_REQUEST['submit1'])){
> echo "button 1 was clicked, act accordingly";
> echo "this the request values";
> echo $_REQUEST['someVal'];
> }elseif(isset($_REQUEST['submit2'])){
> session_start();
> echo "button 2 was clicked, act accordingly";
> $_SESSION['post'] = $_POST;
> header("Location: http://127.0.0.1/Alarms/page5.php?<?=SID?>");
But this is not going to work. You can only redirect with header() if
there has not been any output. That's why you are getting the errors.
--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals – www.phparch.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jan Ruessel Guest



Reply With Quote

