stockton Posted October 22, 2008 Share Posted October 22, 2008 I am having a problem retrieving which button was clicked in my PHP. The following is based on something I found on the internet. The PHP to retrieve the button is:- if (!empty($_REQUEST['submit'])) $Button = ($_REQUEST['submit']); else $Button = ''; but echo ("button = ".$Button); always displays:- button = Submit and the buttons are defined as follows:- <input type="submit" name="submit" value="Submit"> <input type="reset" name="submit" value="Reset"> Please tell me what I misunderstood. Quote Link to comment Share on other sites More sharing options...
trq Posted October 22, 2008 Share Posted October 22, 2008 A button of the type 'reset' will not submit the form, so the only possible button php will know about is the one holding the value 'submit'. Quote Link to comment Share on other sites More sharing options...
stockton Posted October 22, 2008 Author Share Posted October 22, 2008 I did not describe my problem and lack of understanding too well. I was lead to believe that $_REQUEST['submit'] would retrieve the value of the clicked button & if all buttons were defined with name='submit', as I have, one could retrieve the value by $_REQUEST['submit'] and therefore I should, when clicking the reset button, get the value "Reset" returned . As you can see above if I click submit button I get the value "Submit" returned but no such luck with the reset button. NB Look at the capital letters. Quote Link to comment Share on other sites More sharing options...
luca200 Posted October 22, 2008 Share Posted October 22, 2008 I was lead to believe that $_REQUEST['submit'] would retrieve the value of the clicked button That's true but only for buttons of type 'submit'. A 'reset' button will not submit the form, as the admin already said, so you can't retrieve its value at all! You'll never get a php page called because someone hits a 'reset' button. Unless you get it by javascript, of course Quote Link to comment Share on other sites More sharing options...
stockton Posted October 22, 2008 Author Share Posted October 22, 2008 I was getting myself somewhat confused between type, name and value. Thank you, got it working now. 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.