Jump to content

[HELP!] Getting Button Name!?


aiwebs

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.
Link to comment
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;
}
Link to comment
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.
Link to comment
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
Link to comment
Share on other sites

  • 10 months later...
[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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.