TheServant 1,168
Recognized Expert Top Contributor
Hey guys,
Well what I want is to have one form, but two submit buttons. Depending on which submit button is pressed, different code will run.
Here is a short version of my form:
[HTML]<form action="myform.php" method="POST">
<input name="var1" type="text" value="0" size="7" maxlength="6" />
<input name="var2" type="text" value="0" size="7" maxlength="6" />
<input name="var3" type="text" value="0" size="7" maxlength="6" />
<input name="var4" type="text" value="0" size="7" maxlength="6" />
<input name="recruit" type="submit" value="Recruit" />
<input name="disband" type="submit" value="Disband" />
</form>
[/HTML]
The php check:
[PHP]if ( $_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['var1']) && isset($_POST['var2']) && isset($_POST['var3']) && isset($_POST['var4']) )
{ //do stuff
}[/PHP]
So can I add something like && $_submit_name == 'recruit' ???
Also, I know this is a php forum, but do you also know the javascript offhand:
[HTML]if ( document.myform.var1.value == "" && document.myform.var2.value == "" && document.myform.var3.value == "" && document.myform.var4.value == "" )[/HTML]
14 1705 Markus 6,050
Recognized Expert Expert
Hey guys,
Well what I want is to have one form, but two submit buttons. Depending on which submit button is pressed, different code will run.
Here is a short version of my form:
[HTML]<form action="myform.php" method="POST">
<input name="var1" type="text" value="0" size="7" maxlength="6" />
<input name="var2" type="text" value="0" size="7" maxlength="6" />
<input name="var3" type="text" value="0" size="7" maxlength="6" />
<input name="var4" type="text" value="0" size="7" maxlength="6" />
<input name="recruit" type="submit" value="Recruit" />
<input name="disband" type="submit" value="Disband" />
</form>
[/HTML]
The php check:
[PHP]if ( $_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['var1']) && isset($_POST['var2']) && isset($_POST['var3']) && isset($_POST['var4']) )
{ //do stuff
}[/PHP]
So can I add something like && $_submit_name == 'recruit' ???
Also, I know this is a php forum, but do you also know the javascript offhand:
[HTML]if ( document.myform.var1.value == "" && document.myform.var2.value == "" && document.myform.var3.value == "" && document.myform.var4.value == "" )[/HTML]
I don't quite understand your coding.
You check if your text inputs are set, but theyre always set.
Also, i dont understand the usefullness of 'request_method'?
Anyway, how i would do this is:
[php]
if(isset($_POST['recruit']))
{
# do recruit stuff
}
elseif(isset($_POST['disband']))
{
# do disband stuff
}
else
{
# nothing submitted
}
[/php]
use javascript submit()
each button onclick to send different data to the server
use javascript submit()
each button onclick to send different data to the server
I cannot see how javascript could help here and work better than php.
Just take the example markusn00b showed and you'll be fine. JS just clouds this dicusssion.
Ronald
TheServant 1,168
Recognized Expert Top Contributor
I don't quite understand your coding.
You check if your text inputs are set, but theyre always set.
Also, i dont understand the usefullness of 'request_method'?
Cheers markus, yeah you're right about the request_method, it was an old form I was reformatting, forgot to take it out. I will try your code when I get home.
I am concerned about your question about my text inputs...
I have a few chunks of code to { do stuff } so when the form submits information to that file, it will send only the variables contained in that form. So by checking isset() I thought what I was doing was making sure it was the correct information for that function.
ie.
<body>
form1 {var1 var2 var3}
form2 {var4 var5 var6}
</body>
do_stuff.php {form1_function form2_function}
If I submit form1, form1_function checks if var1, 2 and 3 are set (which they are) before it runs, but when the reader gets down to form2_function, var4, 5 and 6 are not set (because I only submitted form1) so it will not run.
Is this not how it works?
Markus 6,050
Recognized Expert Expert
See the below post
Regards.
Markus 6,050
Recognized Expert Expert
Oh, i see.
Well, you can bypass all that with using the way i suggested in my prev. post.
Regards :)
ps: i thought you were checking that the inputs had a value and all of them had to have a value before the IF statement would run - this is flawed because text inputs' are always passed in a form, empty or not.
dlite922 1,584
Recognized Expert Top Contributor
Hey guys,
Well what I want is to have one form, but two submit buttons. Depending on which submit button is pressed, different code will run.
Here is a short version of my form:
[HTML]<form action="myform.php" method="POST">
<input name="var1" type="text" value="0" size="7" maxlength="6" />
<input name="var2" type="text" value="0" size="7" maxlength="6" />
<input name="var3" type="text" value="0" size="7" maxlength="6" />
<input name="var4" type="text" value="0" size="7" maxlength="6" />
<input name="recruit" type="submit" value="Recruit" />
<input name="disband" type="submit" value="Disband" />
</form>
[/HTML]
The php check:
[PHP]if ( $_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['var1']) && isset($_POST['var2']) && isset($_POST['var3']) && isset($_POST['var4']) )
{ //do stuff
}[/PHP]
So can I add something like && $_submit_name == 'recruit' ???
Also, I know this is a php forum, but do you also know the javascript offhand:
[HTML]if ( document.myform.var1.value == "" && document.myform.var2.value == "" && document.myform.var3.value == "" && document.myform.var4.value == "" )[/HTML]
Another way I do it, is the NAME of the buttons are the same but the values are not, so i just get the value of the button and run appropriate action.
[PHP]
<input type="submit" name="pageAction" value="Action One" />
<input type="submit" name="pageAction" value="Action Two" />
[/PHP]
then on php side
[PHP]
if($_POST['pageAction'] == "Action One")
{
// do something
}
else if ($_POST['pageAction'] == "Action Two")
{
// do something else
}
[/PHP]
Anybody know which way is better? I'll change the way markus is doin it if that's better.
Markus 6,050
Recognized Expert Expert
Another way I do it, is the NAME of the buttons are the same but the values are not, so i just get the value of the button and run appropriate action.
[PHP]
<input type="submit" name="pageAction" value="Action One" />
<input type="submit" name="pageAction" value="Action Two" />
[/PHP]
then on php side
[PHP]
if($_POST['pageAction'] == "Action One")
{
// do something
}
else if ($_POST['pageAction'] == "Action Two")
{
// do something else
}
[/PHP]
Anybody know which way is better? I'll change the way markus is doin it if that's better.
There won't be any significant difference; there's just more writing in your way :P
TheServant 1,168
Recognized Expert Top Contributor
Didn't get a chance to try it, but both are logical. I will try both, but thanks for your help guys. Also interesting comment about text inputs markus, I didn't know that.
Markus 6,050
Recognized Expert Expert
Didn't get a chance to try it, but both are logical. I will try both, but thanks for your help guys. Also interesting comment about text inputs markus, I didn't know that.
Ah, no problem ma' man!
TheServant 1,168
Recognized Expert Top Contributor
I don't quite understand your coding.
You check if your text inputs are set, but theyre always set.
Also, i dont understand the usefullness of 'request_method'?
Anyway, how i would do this is:
[php]
if(isset($_POST['recruit']))
{
# do recruit stuff
}
elseif(isset($_POST['disband']))
{
# do disband stuff
}
else
{
# nothing submitted
}
[/php]
I know this is a php forum but do you (markus or anyone else) know how to do the equivalent in javascript?
Markus 6,050
Recognized Expert Expert
I know this is a php forum but do you (markus or anyone else) know how to do the equivalent in javascript?
I can give it a shot: -
function doForm(buttonPressed)
-
{
-
if(buttonPressed == "Recruit")
-
{
-
// do something
-
alert(buttonPressed);
-
}
-
else // 'disband' was pressed
-
{
-
# do something
-
alert(buttonPressed);
-
}
-
}
-
-
<form name="someForm" method="post" action="page.php">
-
<input type="text" name=" ...
-
-
-
-
-
<input type="submit" name="recruit" onclick="doForm(this.value)" value="recruit" />
-
-
<!-- you get the idea.. //-->
-
-
I'm not expert with javascript though, so maybe you should ask over there?
TheServant 1,168
Recognized Expert Top Contributor
I can give it a shot: -
function doForm(buttonPressed)
-
{
-
if(buttonPressed == "Recruit")
-
{
-
// do something
-
alert(buttonPressed);
-
}
-
else // 'disband' was pressed
-
{
-
# do something
-
alert(buttonPressed);
-
}
-
}
-
-
<form name="someForm" method="post" action="page.php">
-
<input type="text" name=" ...
-
-
-
-
-
<input type="submit" name="recruit" onclick="doForm(this.value)" value="recruit" />
-
-
<!-- you get the idea.. //-->
-
-
I'm not expert with javascript though, so maybe you should ask over there?
Sounds good, I will give it a go, but make a post... " OVER THERE"... on the other side (excuse the pun).
Another way I do it, is the NAME of the buttons are the same but the values are not, so i just get the value of the button and run appropriate action.
[PHP]
<input type="submit" name="pageAction" value="Action One" />
<input type="submit" name="pageAction" value="Action Two" />
[/PHP]
then on php side
[PHP]
if($_POST['pageAction'] == "Action One")
{
// do something
}
else if ($_POST['pageAction'] == "Action Two")
{
// do something else
}
[/PHP]
Anybody know which way is better? I'll change the way markus is doin it if that's better.
You Da Man. Works for me!!!!
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Robert V |
last post by:
Hi all, I could use some help programming on of my Perl script to handle
different submit buttons within the same form. Here is what I have so far.
A user goes to a Web form and inputs some data...
|
by: James Baker |
last post by:
Once again, trying to re-learn ASP with all of my might. Probably a simple
problem, but here goes:
I have a form that current has a fair amount of data/input tags and a button
that submits it...
|
by: news |
last post by:
I seriously doubt this is possible...but you never know, so here goes.
Due to bad pre-planning I have a Web page that is VERY table heavy with
a very complicated and delicate setup. Any changes...
|
by: Mad Scientist Jr |
last post by:
I'm stuck trying to work with a HTML <SELECT> control and javascript
(similar to DualList but that control doesn't offer enough options to
totally control the text on the buttons and control, also...
|
by: Peet |
last post by:
Hi there,
Do somebody have some ideas about this behaviour?
I have a struts application. It has a jsp which has a form and two
buttons, one of them is html:submit, and the other is...
| |
by: Hul Tytus |
last post by:
comp.infosystems.www.authoring.html
multiple submits
When multiple submit lines are placed in an HTML form, the string returned
to the server shows the name=value field for each one with no...
|
by: harshmaul |
last post by:
Hi all,
I have a problem.
I have a search box on the top of all of my pages, and on various other pages i have forms that do other fancy stuff. However this has given rise to the bug.
If i...
|
by: Plater |
last post by:
I'm going to stab myself in the face.
I have a page with a single form.
Regular old html.
There are a few checkboxes and textboxes and and two submit buttons (I hope that's not the issue...)
The...
|
by: 0utlawza |
last post by:
Hi Guys
It seems i posted this in the incorrect topic, so i am reposting here.
Please excuse the Newbie question. I am not really a programmer so excuse me if i dont clarify my point...
|
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...
|
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: 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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |