Home  >  Article  >  Backend Development  >  Validation method for multiple submission forms

Validation method for multiple submission forms

巴扎黑
巴扎黑Original
2016-12-01 09:51:301436browse

Sometimes we need to submit a form from one page to a different page. The processing method is generally to dynamically give the action value in the onClick event, as in the following example:

94d6dd44a44e7c0bf656b9e3f20b3e02

417091cb7805976559e397fa142e1da7
3cd015235340caa036634e515c3741f5
3b675b543bf0be81309e8438b6839b60
67c47c2f4e2e39e829bbcfb43fc3cadb

At this time, the verification of the form for different submission targets can only be placed in the onClick event, but this causes the problem that the form will be submitted regardless of whether it passes verification or not. Because this button is of submit type.

My solution to this problem is this:

<script language="JavaScript"><!--
document.returnValue=true;//一个全局变量,给初值。
function validateForm() { var errors;errors=&#39;&#39;;if (document.PostTopic.title.value=="")errors="标题不能为空";if( document.PostTopic.intro.value.length>10)errors+="\n简介不能多于10个字";if (errors!=&#39;&#39;) alert(errors);document.returnValue = (errors == &#39;&#39;);}
file://--></script>
<FORM ACTION="" METHOD="post" NAME="PostTopic" onSubmit="return document.returnValue;"><input type=text name=title value=""><input type=text name=intro value=""><INPUT TYPE="submit" NAME=Submit VALUE="新增" class=buttonface onclick="document.PostTopic.action=&#39;addone.php&#39;;validateForm(); return document.returnValue;"><INPUT TYPE="RESET" NAME=Reset VALUE="重置" class=buttonface ><INPUT TYPE="submit" NAME="Submit" VALUE="修改" class=buttonface onclick="document.PostTopic.action=&#39;modify.php&#39;;validateForm(); return document.returnValue;"></FORM>


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