Re: Using custom "button" form element instead of standard "submit"?

From: Date: Thu, 30 Jan 2003 12:37:42 +0000
Subject: Re: Using custom "button" form element instead of standard "submit"?
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-133636@lists.php.net to get a copy of this message
> <input type="submit" name="sample_a"> > <input type="image" name="sample_b" src="myimg.gif"> > > With the first method, you'd need to test for a button named 'sample_a'. > For the second method, you'd need to test for a button named 'sample_b_x'. no ... with the first example you can have numerous buttons on the same HTML page with the same name and use the 'value' attribute to see which one is pressed. I did this and it works quite elegantly for my application. <input type="submit" name="sample" value="a" > <input type="submit" name="sample" value="b" > <input type="submit" name="sample" value="c" > <input type="submit" name="sample" value="d" > your php form handler can now simply do: print "The user selected button $sample<br>\n") otherwise, with the image solution you'd have to do something like this... foreach ($_GET as $button) { if (isset($button)) { $button_name = substr($button, -2, 0); // or whatever to remove the _x print "The user selected button substr($button_name); break; } } Although arrays might provide a solution that wouldn't quite be as good as the 'submit' button solution, but not as worse as a straight name-based 'image' solution. Given that the 'button' element with "type = submit" does NOT work, maybe the javascript solution is the most elegant. but i haven't gotten that to work yet either!

« previous php.general (#133636) next »