Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder stevenmw's Avatar
    Join Date
    Jun 2007
    Location
    OK
    Posts
    497
    Thanks
    27
    Thanked 31 Times in 31 Posts

    Check If Form Doesnt Submit

    To check if a form submitted you could do something like.

    PHP Code:
    If (isset($_POST['submit'])) 
    {

    But how can you check if the form DOESN'T submit?

    Say I wanted to do something similar to.

    if form doesn't submit echo failure message
    elseif run this command

    Thanks,
    Steven

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    You would use an else statement or negate the isset with a !.
    Older versions of IE are flawed in that they do not guarantee providing the successful submit entry. So if that is an actual submit button and its submitted by pressing the enter key in a non-multiline input, it will neglect sending the submit entry with the successful fields.

  • #3
    Regular Coder stevenmw's Avatar
    Join Date
    Jun 2007
    Location
    OK
    Posts
    497
    Thanks
    27
    Thanked 31 Times in 31 Posts
    So this will allow hitting the enter key

    PHP Code:
    if (!($_POST['submit'])) 
    ?


    Is it considered sloppy coding if I put an if statement inside an if statement?
    Last edited by stevenmw; 08-21-2011 at 05:37 PM.

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,089
    Thanks
    51
    Thanked 506 Times in 493 Posts
    PHP Code:
    if (!isset($_POST['submit']))
       {
       
    //Form not submitted
       
    }

    //OR
    if (isset($_POST['submit']))
       {
       
    //Form submitted
       
    }
    else
       {
       
    //Form not submitted.
       

    Also you should listen to what Fou-Lou has said to you about checking for the submit button in your code. Internet explorer (v4, 5, 6, 7, and I believe v8) do not send the submit button when your users hits the return key when the cursor is inside a text box in your form. It will only send the button value when the button is physically clicked with the mouse. You're best checking for a hidden form field OR another element that your user is guaranteed to use.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • Users who have thanked tangoforce for this post:

    stevenmw (08-21-2011)

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    No it won't. Old versions of IE just don't submit it, even though its against the form standards.
    You need to check the isset conditions of all the fields you are expecting to be there instead of the submit button.
    As for your if branches, there is almost no limit on how far you want to go.

  • #6
    Regular Coder stevenmw's Avatar
    Join Date
    Jun 2007
    Location
    OK
    Posts
    497
    Thanks
    27
    Thanked 31 Times in 31 Posts
    So what exactly does the exclamation mark actually do?

    Would I need to use a hidden field in my html?

    For instance.

    Code:
    <input type='hidden' name='submit' />
    Last edited by stevenmw; 08-21-2011 at 05:49 PM.

  • #7
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,089
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Yes that hidden field will do it but you'll have to give it a value - like this
    <input type="hidden" name="submit" value="1">

    The ! as Fou explained negates the value of whatever you're checking. In otherwords it makes it the opposite or NOT.

    So.. true would become false and false would become true. In otherwords ! makes the if look for the opposite of true.

    Thats about the only easy way I can explain it.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • Users who have thanked tangoforce for this post:

    stevenmw (08-21-2011)

  • #8
    Regular Coder stevenmw's Avatar
    Join Date
    Jun 2007
    Location
    OK
    Posts
    497
    Thanks
    27
    Thanked 31 Times in 31 Posts
    Wow, thanks guys.

  • #9
    New Coder
    Join Date
    Apr 2010
    Posts
    55
    Thanks
    0
    Thanked 4 Times in 4 Posts
    silly question, indeed Okay, may not be so for newbies..
    if(! ...)
    if()
    else.. everything works!
    Hosting Reviews and Discounts: Bluehost Coupon and Hostmonster Coupon


  •  

    Posting Permissions

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