How to protect HTML form from blank submission

前端 未结 5 1962
梦毁少年i
梦毁少年i 2021-01-15 15:59

Basically I\'m using this tutorial: HTML FORM

Everything is working as it should but one flow I\'ve found is that everyone can see the URL for your

5条回答
  •  不思量自难忘°
    2021-01-15 16:32

    Form blank submission you can use java-script validation or jquery validation validation or you can also use php validation to avoid blank form submission.

    core js validation

    simple example:

       var x = document.forms["myForm"]["fname"].value;
       if (x == "") {
          alert("Name must be filled out");
          return false;
       }
    

    jquery validation

    validation library https://jqueryvalidation.org/documentation/

    example:

    $("#myform").validate({
         submitHandler: function(form) {
         // some other code
         // maybe disabling submit button
         // then:
         $(form).submit();
       }
      });
    

    I hope it helps.

提交回复
热议问题