Jump to content

Archived

This topic is now archived and is closed to further replies.

aiwebs

[HELP!] Getting Button Name!?

Recommended Posts

Okay I'll try to explain this,

What I want to do is to have a script/function that will get the name of the input button that is push. Here is what i want to do... if there is an easier way then PLEASE let me know...

if (!isset($_POST[[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]button_name[!--colorc--][/span][!--/colorc--]])){
$mode = "empty";
}
switch($_POST[[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]button_name[!--colorc--][/span][!--/colorc--]]) {
case 'index':
echo "Sorry, you didnt select a item to process";
break;
case 'register':
// This would process the signup part...
break;
}

Now a little more,
The parts in red I would like it to get automaticly, so what it will do is just jump straight to where it is ment to start processing information. Saving me from typing;

if($_POST['blah']) {
blah
} elseif ($_POST['blahblah']) {
blah blah
}


Please ask me to explain better if you cannot understand it, I am pretty tired hacking away at this for a while and havnt got very far.

Share this post


Link to post
Share on other sites
The name of your submit button is not passed as a post variable. Only the form fields are passed.

If you have multiple buttons, you must be using multiple forms, yes?

if that is the case, on every form, have a hidden field with the same name, but a different value.

eg.
index form
<input type="hidden" name="hidden_field" value="index">

register form
<input type="hidden" name="hidden_field" value="register">

You could then use your switch

switch($_POST[hidden_field]) {
case 'index':
echo "Sorry, you didnt select a item to process";
break;
case 'register':
// This would process the signup part...
break;
}

Share this post


Link to post
Share on other sites
i would recommend a modification to the above thoughts... if you have one single hidden input field named "submitValue" or something similar, you can use javascript to take the name of the pressed button and insert it into the value of that field for submission. then, you'll have one field you can always look at to immediately tell which button was pressed.

Share this post


Link to post
Share on other sites
another alternative would be to get the referring page to find out which page they came from.

Share this post


Link to post
Share on other sites
wisewood wrote:[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]The name of your submit button is not passed as a post variable. Only the form fields are passed.[/quote]
The submit button is passed as a Post variable just as any form variable as long as you give it a name.

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]If you have multiple buttons, you must be using multiple forms, yes?[/quote]
You can have multiple submit buttons on a form, each one having a different value. I've done this many times.

Ken

Share this post


Link to post
Share on other sites
Thanks guys I'll give your sugestions a go!!

Share this post


Link to post
Share on other sites
[quote author=jdadwilson link=topic=95329.msg590444#msg590444 date=1178241045]
Is it possible to obtain the button name/value when you have one form and multiple buttons?
[/quote]

You can loop through all input fields and get the name/value for each or all of them, but without [b]some[/b] way to reference a specific element, you won't know when you get to the one you're after.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.