Home >Backend Development >PHP Tutorial >Code to process the data and then submit the form

Code to process the data and then submit the form

不言
不言Original
2018-07-18 15:32:551343browse

The content introduced below is applicable when the form information on the front-end page is not filled in before submitting or saving.

When the information is empty, generally we must not submit the form to The database should prompt that the information is not filled in or empty. This step can be completed by the front end or the back end. However, in order to reduce the burden on the server, it is recommended that the front end complete the judgment.

function check(){
   var name = document.getElementById("name").value;   
   if(name ==  null || name == ''){
        alert("用户名不能为空");
        return false;
   }
   return true;
}

<form name="mainform" action="form.php" method="post"  onsubmit="return check()">
  <input type="text" id="name"/>
  <input type="sumit" value="提交"/>
</form>

onsubmit="return check() "The return in " must be added, otherwise even if the return value of check is false, it will still be submitted. In other words, onsubmit="return false" does not execute submission; onsubmit="return true" or onsubmit="return" both execute submission.

Related recommendations:

php prevents form submission from being repeated, php prevents form submission

The above is the detailed content of Code to process the data and then submit the form. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn