aiwebs Posted June 8, 2006 Share Posted June 8, 2006 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. Quote Link to comment Share on other sites More sharing options...
wisewood Posted June 8, 2006 Share Posted June 8, 2006 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 switchswitch($_POST[hidden_field]) {case 'index':echo "Sorry, you didnt select a item to process";break;case 'register':// This would process the signup part...break;} Quote Link to comment Share on other sites More sharing options...
obsidian Posted June 8, 2006 Share Posted June 8, 2006 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. Quote Link to comment Share on other sites More sharing options...
wisewood Posted June 8, 2006 Share Posted June 8, 2006 another alternative would be to get the referring page to find out which page they came from. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 8, 2006 Share Posted June 8, 2006 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 Quote Link to comment Share on other sites More sharing options...
aiwebs Posted June 9, 2006 Author Share Posted June 9, 2006 Thanks guys I'll give your sugestions a go!! Quote Link to comment Share on other sites More sharing options...
jdadwilson Posted May 4, 2007 Share Posted May 4, 2007 Is it possible to obtain the button name/value when you have one form and multiple buttons? Quote Link to comment Share on other sites More sharing options...
obsidian Posted May 4, 2007 Share Posted May 4, 2007 [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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.