How do I make that if the form is empty, it cannot submit?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • moishy
    New Member
    • Oct 2006
    • 104

    How do I make that if the form is empty, it cannot submit?

    Hi! I'm making an order form where the customers fill out the desired quantity, and the form is emailed to me.
    But they also must fill out their contact info.

    So How do I make it, that if they havn't filled out fields A, B, or C - the page will just refresh, and not Submit.


    Thanks in advance folks.
  • mainul
    New Member
    • Sep 2006
    • 51

    #2
    Hey you can try this code.


    <?php if(empty($_POST['A'] ||$_POST['B'] ||$_POST['C'])){ // names from the form feild
    print 'error go back';
    // if you want to go back to the orignal form with messages like that i would use a session or hidden feilds to pass back the orignal data sent and the error message to print
    }else{
    //sendl script or whatever you need to do
    }
    ?>

    Comment

    • moishy
      New Member
      • Oct 2006
      • 104

      #3
      Originally posted by mainul
      Hey you can try this code.
      Yeah, I tryed it but the error is:
      Parse error: syntax error, unexpected T_BOOLEAN_OR, expecting ')'

      Any help?

      Comment

      • bevort
        New Member
        • Jul 2006
        • 53

        #4
        Use Javascript or VB script
        First start with a disabled button.
        Then, with the onChange() event remove the disabled status if a user chahges the content of a field.
        Do not forget to check with the onSubmit() event if at least one field has some content

        A standard rule should be to do on the client side what can be done there instead of doing it on the server

        Comment

        • ronverdonk
          Recognized Expert Specialist
          • Jul 2006
          • 4259

          #5
          A standard rule should be to do on the client side what can be done there instead of doing it on the server
          Where is that rule written?
          What about security issues on a client?
          What if JavaScript is disabled on the client?

          Ronald :cool:

          Comment

          Working...