Web Analytics Made Easy -
StatCounter Check If Form Doesnt Submit - CodingForum

Announcement

Collapse
No announcement yet.

Check If Form Doesnt Submit

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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
    Thanks!

  • #2
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

    Comment


    • #3
      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; Aug 21, 2011, 12:37 PM.
      Thanks!

      Comment


      • #4
        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.
        "Tango says double quotes with a single ( ' ) quote in the middle"
        '$Name says single quotes with a double ( " ) quote in the middle'
        "Tango says double quotes ( \" ) must escape a double quote"
        '$Name single quotes ( \' ) must escape a single quote'

        Comment


        • #5
          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.
          PHP Code:
          header('HTTP/1.1 420 Enhance Your Calm'); 
          Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

          Comment


          • #6
            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; Aug 21, 2011, 12:49 PM.
            Thanks!

            Comment


            • #7
              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.
              "Tango says double quotes with a single ( ' ) quote in the middle"
              '$Name says single quotes with a double ( " ) quote in the middle'
              "Tango says double quotes ( \" ) must escape a double quote"
              '$Name single quotes ( \' ) must escape a single quote'

              Comment


              • #8
                Wow, thanks guys.
                Thanks!

                Comment


                • #9
                  silly question, indeed Okay, may not be so for newbies..
                  if(! ...)
                  if()
                  else.. everything works!
                  Hosting Reviews and Discounts: Bluehost Coupon and Hostmonster Coupon

                  Comment

                  Working...
                  X