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. Link to comment https://forums.phpfreaks.com/topic/129562-solved-identifying-which-button-was-clicked/ 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'. Link to comment https://forums.phpfreaks.com/topic/129562-solved-identifying-which-button-was-clicked/#findComment-671679 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. Link to comment https://forums.phpfreaks.com/topic/129562-solved-identifying-which-button-was-clicked/#findComment-671691 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 Link to comment https://forums.phpfreaks.com/topic/129562-solved-identifying-which-button-was-clicked/#findComment-671700 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. Link to comment https://forums.phpfreaks.com/topic/129562-solved-identifying-which-button-was-clicked/#findComment-671716 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.