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.

 

 

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.