Jump to content


Photo

[HELP!] Getting Button Name!?


  • Please log in to reply
7 replies to this topic

#1 aiwebs

aiwebs
  • Members
  • Pip
  • Newbie
  • 5 posts
  • LocationNew Zealand

Posted 08 June 2006 - 12:12 PM

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.

#2 wisewood

wisewood
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts
  • LocationRotherham, England

Posted 08 June 2006 - 12:28 PM

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;
}

wisewood: proven fact, I am both wise, and wooden.

#3 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 08 June 2006 - 12:41 PM

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.
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#4 wisewood

wisewood
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts
  • LocationRotherham, England

Posted 08 June 2006 - 12:43 PM

another alternative would be to get the referring page to find out which page they came from.
wisewood: proven fact, I am both wise, and wooden.

#5 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 08 June 2006 - 03:42 PM

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

#6 aiwebs

aiwebs
  • Members
  • Pip
  • Newbie
  • 5 posts
  • LocationNew Zealand

Posted 09 June 2006 - 02:43 AM

Thanks guys I'll give your sugestions a go!!

#7 jdadwilson

jdadwilson
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 04 May 2007 - 01:10 AM

Is it possible to obtain the button name/value when you have one form and multiple buttons?

#8 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 04 May 2007 - 01:24 AM

Is it possible to obtain the button name/value when you have one form and multiple buttons?


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

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users