www.webdeveloper.com
Results 1 to 6 of 6

Thread: using input type="button" does not work with if(isset($_POST['button-name']))

  1. #1
    Join Date
    Mar 2010
    Posts
    281

    using input type="button" does not work with if(isset($_POST['button-name']))

    Here's something i was trying tonight.

    A form with 3 buttons(!).
    I kept all 3 in the same <form> element just to see,...

    the first button, submit works as expected,
    using
    PHP Code:
    if(isset($_POST['submit'])) 
    the second button at first i had coded like this:
    PHP Code:
    <input type="button" name="reset-page-copy" value="reset to default" /> 
    when coded as type="button" it did not respond to this...

    PHP Code:
    if(isset($_POST['reset-page-copy'])) {
    //run some code

    but when coding as type="submit" or .....
    PHP Code:
    <input type="submit" name="reset-page-copy" value="reset to default" /> 
    ...the if isset statement worked.

    why is that?? i never came across this before.
    and how can i use input type="button" instead of input type="submit" ??

    big thanks everyone

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,634
    You could add a type="hidden" input element to check for.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Mar 2010
    Posts
    281
    thanks but not sure what you mean. check for what?,

    it's not critical of course, i can use input type="submit" instead of input type="button" but am curious why,... what that difference is,

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,634
    Frankly, I've never used type="button", so I'm not sure if you are encountering a browser-specific problem or a general HTML issue. What does a button-type provide for you that a submit-type does not? Alternatively, you could use a button element with type="submit", perhaps?
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Jun 2012
    Location
    FL, USA
    Posts
    48
    i don't think buttons get 'set'. They're just there, see?

    What you need is something like was_pressed($_POST[your_button])

    So PHP doesn't really deal with that as far as I know. You can use javascript:

    <input type="button" name="mybutton" id="mybutton" onclick="dostuff()" />

    <script language="javascript">
    function dostuff()
    {
    // the code you want done when the button gets clicked
    }
    </script>


    By the way there is an <input type="reset" ... /> that will reset all fields in the form to their original values FOR you, if you didn't know
    Last edited by captainscall; 07-22-2012 at 04:37 PM.

  6. #6
    Join Date
    Mar 2010
    Posts
    281
    thanks guys.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles