Jump to content

[SOLVED] Identifying which button was clicked


stockton

Recommended Posts

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.

 

 

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.