473,883 Members | 1,787 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 14761
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("Locatio n: ...")? 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="javas cript">
function subby_one()
{
document.aform. action="paul.ph p";
}
function subby_two()
{
document.aform. action="robert. php";
}
</script>
<form action="fred.ph p" 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**********@n oaa.gov> wrote in message
news:e0******** **@news.nems.no aa.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***@bhg byrzcv.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**********@n oaa.gov> wrote in message
news:e0******** **@news.nems.no aa.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**@andyjeffr ies.co.uk> wrote in message
news:pa******** *************** *****@andyjeffr ies.co.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.getEle mentById(id); x.action =
"blah.php". Use that in accordance to a certain action of the form (like
choosing a ratio button).

"Mark" <Ma**********@n oaa.gov> wrote in message
news:e0******** **@news.nems.no aa.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.a ction='page1.ph p';"/>
<input type="submit" name="submit" value="goto page 2"
onClick="form.a ction='page2.ph p';"/>
</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.formna me.action=blalb a.

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
2900
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. Value selected is used as the 'where' clause of the 2nd query. If $site is a single word, the 2nd query works like a charm. If $site is more than one word (has spaces), the query returns a null
3
7022
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 submit to the current page, however, when the user clicks on the submit button, I'd like the form to submit to another processing page. In other words, I basically want two distinct form actions -- one to
2
2117
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 function to submit the form data. However, it didn't work properly and I changed to use SUBMIT type. <INPUT TYPE="BUTTON" NAME="action1" VALUE="Return to Main Search Page" onClick="action1()">
1
1737
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 via a php function call (<? php echo $editFormAction; ?>. Both actions work; however, only the second action in the fucntion runs. Here is the code: <script language=javascript> <!--
8
4798
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
2025
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 originally directed to an .asp file on a remote server, which updates a database and sends a copy of the form via mail.(For various reasons, the remote server with its ASP script must do the form processing). To use the image verification, the form...
4
1538
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 perform complex analyses on the selected members. I'd prefer to keep this code seperated from the basic form processing, opening a new page with the results.
0
1847
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 using urllib & urllib2 to open the page and re to parse the info. On the page is a text entry field and a 'submit' button. I've compared the source code of both pages and they appear the same as far as the submission goes. Anything else I can try? I...
3
1863
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" action="http://www.autoresponder.com"> When i submit this form it goes to the page http://www.autoresponder.com .Along with this i want to run some extra functionality(mail sending) after the form submission .like <? //test mail
0
9796
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10757
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10420
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7975
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7134
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5804
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6002
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4620
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4225
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.