473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

1 Form, 2 Actions?

I have a lengthy form (i.e., many inputs) on my form.php page. What's
different about this form than many others I've created is that I want
the user to have a choice of submitting this form data to one of two
pages, choice1.php or choice2.php, both of which read $_POST data from
the form.

Obviously, a 'submit' button will send the user to the page specified by
the form's 'action=' setting, so I would have to employ some sort of
trick. But this is where I'm drawing a blank! What combination of PHP,
Javascript, and HTML would do the trick?

Thanks!
Mark
Mar 30 '06 #1
9 14664
simply:

Have the form post to submitted.php in there save the variables check
which page it needs to be sent to and use the redirect function to call
the relevant page.. (may have to make the variables global, or it may
still pick them up in the session i can't test at the moment.

Think that should do what you require.

Mar 30 '06 #2
ally666 wrote:
simply:

Have the form post to submitted.php in there save the variables check
which page it needs to be sent to and use the redirect function to call
the relevant page..
I think by "redirect function" you mean header("Location: ...")? That
is not a good idea.
If the form is post, and contains a lot of data, then the redirect wont
work because it's a "get". You would need to use something like curl,
to re POST the data.

(may have to make the variables global, or it may still pick them up in the session i can't test at the moment.
eh? No, just use what ever you give to the script. Personally, I never
use globals, they're a sick idea and to be avoided like the plague.
Think that should do what you require.


It will now ;o)

Also, you could change the form action using Javascript. Something
similar to:

<script language="javascript">
function subby_one()
{
document.aform.action="paul.php";
}
function subby_two()
{
document.aform.action="robert.php";
}
</script>
<form action="fred.php" id="aform">
<input type="button" name="butt" onclick="subby_one()">
<<input type="button" name="butt" onclick="subby_two()">
</form>
type of thing... I'm a "trial by error" type of javascript coder, so
that may take a few attempts to get right ;o)

Mar 30 '06 #3
"Mark" <Ma**********@noaa.gov> wrote in message
news:e0**********@news.nems.noaa.gov...
I have a lengthy form (i.e., many inputs) on my form.php page. What's
different about this form than many others I've created is that I want the
user to have a choice of submitting this form data to one of two pages,
choice1.php or choice2.php, both of which read $_POST data from the form.

Obviously, a 'submit' button will send the user to the page specified by
the form's 'action=' setting, so I would have to employ some sort of
trick. But this is where I'm drawing a blank! What combination of PHP,
Javascript, and HTML would do the trick?

Set the action to page3.php which has only the following:
<?php
if(isset($_POST['submit1']))
include('page1.php');
else if(isset($_POST['submit2']))
include('page2.php');
?>

And in the form you naturally have

<input type="submit" name="submit1" value="1">
<input type="submit" name="submit2" value="2">

--
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
sp**@outolempi.net | Gedoon-S @ IRCnet | rot13(xv***@bhgbyrzcv.arg)
Mar 30 '06 #4
Kimmo Laine wrote:
Set the action to page3.php which has only the following:
<?php
if(isset($_POST['submit1']))
include('page1.php');
else if(isset($_POST['submit2']))
include('page2.php');
?>

And in the form you naturally have

<input type="submit" name="submit1" value="1">
<input type="submit" name="submit2" value="2">


Which presumes thes destination "action" is on his server. I'd think
that just by the fact that he's wanting to do it this way, would
suggest that the target form is on another box?

Mar 30 '06 #5
I don't see what the problem is. It is possible to have more than one submit
button on any form, with each one having a unique name instead of 'submit'.
So if you have a form with 'buttonA', 'buttonB' and 'buttonC' when the user
presses one of those buttons that will be the ONLY one to appear in the POST
array. I have been using this technique for years, so don't tell me that it
doesn't work.

--
Tony Marston

http://www.tonymarston.net
"Mark" <Ma**********@noaa.gov> wrote in message
news:e0**********@news.nems.noaa.gov...
I have a lengthy form (i.e., many inputs) on my form.php page. What's
different about this form than many others I've created is that I want the
user to have a choice of submitting this form data to one of two pages,
choice1.php or choice2.php, both of which read $_POST data from the form.

Obviously, a 'submit' button will send the user to the page specified by
the form's 'action=' setting, so I would have to employ some sort of
trick. But this is where I'm drawing a blank! What combination of PHP,
Javascript, and HTML would do the trick?

Thanks!
Mark

Mar 30 '06 #6
On Thu, 30 Mar 2006 20:00:37 +0100, Tony Marston wrote:
I don't see what the problem is. It is possible to have more than one
submit button on any form, with each one having a unique name instead of
'submit'. So if you have a form with 'buttonA', 'buttonB' and 'buttonC'
when the user presses one of those buttons that will be the ONLY one to
appear in the POST array. I have been using this technique for years, so
don't tell me that it doesn't work.


Congratulations...now tell me, did you actually read the post you're
responding to?

He didn't ask about having multiple submit buttons but about having
multiple form actions (target scripts) depending on which button is
pressed.

Re-read and try again...

Regards,
Andy
--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos

Mar 30 '06 #7
The solution is to post to the same form which then stores its data in the
$_SESSION array before passing control to the actual form identified on one
of the submit buttons. The next form, which could be one of several, simply
picks up its data from the $_SESSION array instead of the POST array. This
can be done with standard PHP code without the need for any fancy and
dubious tricks with javascript.

It's not rocket science, just lateral thinking.

--
Tony Marston
http://www.tonymarston.net

"Andy Jeffries" <ne**@andyjeffries.co.uk> wrote in message
news:pa****************************@andyjeffries.c o.uk...
On Thu, 30 Mar 2006 20:00:37 +0100, Tony Marston wrote:
I don't see what the problem is. It is possible to have more than one
submit button on any form, with each one having a unique name instead of
'submit'. So if you have a form with 'buttonA', 'buttonB' and 'buttonC'
when the user presses one of those buttons that will be the ONLY one to
appear in the POST array. I have been using this technique for years, so
don't tell me that it doesn't work.


Congratulations...now tell me, did you actually read the post you're
responding to?

He didn't ask about having multiple submit buttons but about having
multiple form actions (target scripts) depending on which button is
pressed.

Re-read and try again...

Regards,
Andy
--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos

Mar 30 '06 #8
You can use JavaScript to change the action of the form. Just name the form
(with id), and use a x = document.getElementById(id); x.action =
"blah.php". Use that in accordance to a certain action of the form (like
choosing a ratio button).

"Mark" <Ma**********@noaa.gov> wrote in message
news:e0**********@news.nems.noaa.gov...
I have a lengthy form (i.e., many inputs) on my form.php page. What's
different about this form than many others I've created is that I want the
user to have a choice of submitting this form data to one of two pages,
choice1.php or choice2.php, both of which read $_POST data from the form.

Obviously, a 'submit' button will send the user to the page specified by
the form's 'action=' setting, so I would have to employ some sort of
trick. But this is where I'm drawing a blank! What combination of PHP,
Javascript, and HTML would do the trick?

Thanks!
Mark

Mar 30 '06 #9
Two ways:
You can change the form action using javascript (easy and clean,
really), or
You can read the submit buttons value and proceed accordingly.

The first sounds more like what you want.

Case 1:
<form>
<input fields>
<input type="submit" name="submit" value="goto page 1"
onClick="form.action='page1.php';"/>
<input type="submit" name="submit" value="goto page 2"
onClick="form.action='page2.php';"/>
</form>

The javascript in the onClick handler of the submit buttons inherits
'form' from the current form they are in, avoiding the use of having to
do getElementByID() or document.formname.action=blalba.

Case2:

<form action="mypage.php">
<input fields>
<input type="submit" name="submit" value="goto page 1"/>
<input type="submit" name="submit" value="goto page 2"/>
</form>

mypage.php :
<? if($submit == 'goto page 1') { process according to page 1's method
} else { process according to page 2's method } ?>
Obviously this wouldn't work unless the code for both pages could be
consolidated into that single page, in which case you would be better
off using case 1.

Mar 31 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: dogu | last post by:
Noob alert. Code is below. File is saved as a .php. What I'm trying to do: User uses 'select' box drop down list to pick a value. Value ($site) is derived from a db query. This works fine....
3
by: M Wells | last post by:
Hi All, I'm trying to build a page where a user can enter comments and I want to add a 'Preview' button to the form. When the user clicks on the 'Preview' button I'd like the same form to...
2
by: Matt | last post by:
The ASP page has multiple buttons, and when the user clicks different buttons, it will submit the form data to different URLs. My first approach was to use BUTTON type, and triggers javascript...
1
by: Sophisticado | last post by:
Hi Newbie here. I am trying to have two form actions on submission using a javascript. The first calls a php class (http://www.blah.org/test.php) and the second adds data to a mySQL database...
8
by: yawnmoth | last post by:
Say I have the following HTML: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title></title> </head> <body> <form action="">
3
clintw
by: clintw | last post by:
My problem. I have a html contact form that is being spammed. So I have set .html to be treated as .php, in order to include php image verification into the form. However, the Action on the form...
4
by: Peter Bremer | last post by:
Hi all, I've got a form which lists all members of a club, with checkboxes to select them. The form offers functions to delete selected members, send email, etc. Now I want write some code to...
0
Thekid
by: Thekid | last post by:
I'm trying to auto send a form submission to a website but it isn't working. I've done this before and it worked but for some reason, using the same basic code, it doesn't seem to submit it. I'm...
3
by: swethak | last post by:
Hi, I am getting the problem with form tag. i,e in in form action i am placing the some autoresponder page like <form name="form1" method="post"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.