Dave's Brain

Browse - Programming Tips - How can I get two different responses from a submit?

Date: 2016nov21
Platform: web
Language: php, html

Q.  How can I get two different responses from a submit?

A.  The trick is to type=submit's with the same name but different value's

<form> ... <input type=submit name=form_reply value=Yes> <input type=submit name=form_reply value=No> </form>
The user will see two buttons: [Yes] [No] And your server-side code will get form_reply=Yes or form_reply=No In php:
$reply = strtolower($_REQUEST['form_reply']); if ($reply == 'yes') { doYes(); } else if ($reply == 'no') { doNo(); } else { print "Unknown reply"; }
A potential problem with this approach is translation. What you are displaying to the user might change to "Oui" and "Non".

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.