Home  >  Article  >  CMS Tutorial  >  How to modify the required fields of custom form options in dedecms

How to modify the required fields of custom form options in dedecms

藏色散人
藏色散人Original
2019-12-19 09:31:392312browse

How to modify the required fields of custom form options in dedecms

How to modify the required fields in dedecms custom form options?

The example in this article describes the solution to the required modification of custom form options in dedecms. Share it with everyone for your reference. The specific method is as follows:

Recommended learning: 梦Weavercms

Method 1: First, we need to use a piece of php code to determine the required verification options.

1. Let’s first add the following code under line 40 in the plus/diy.php file:

The code is as follows:

//增加必填字段判断 
if($required!=''){ 
if(preg_match('/,/', $required)) 
{ 
$requireds = explode(',',$required); 
foreach($requireds as $field){ 
if($$field==''){ 
showMsg('带*号的为必填内容,请正确填写', '-1'); 
exit(); //phpfensi.com 
} 
} 
}else{ 
if($required==''){ 
showMsg('带*号的为必填内容,请正确填写', '-1'); 
exit(); 
} 
} 
} 
//end

2. After saving, find this on the form page Line of code.

The code is as follows:

<form action="/plus/diy.php" enctype="multipart/form-data" method="post" style="padding: 0px; margin: 0px; " >`````

Under this line of code, add the code:

The code is as follows:

<input type="hidden" name="required" value="content,name,tel" />````

Method 2: I finally It is implemented in another way, add a JQ and a JS to your form page:

The code is as follows:

<script src="js/jquery-1.8.0.js"></p> <p><script src=&#39;{dede:global.cfg_templets_skin/}/style/js/js.js&#39; type="text/javascript">

The content of this js is:

The code is as follows :

<!-- 
$(document).ready(function() 
{ 
//验证 
$(&#39;#complain&#39;).submit(function () 
{ 
if($(&#39;#yname&#39;).val()==""){ 
$(&#39;#yname&#39;).focus(); 
alert("姓名不能为空!"); 
return false; 
} 
if($(&#39;#qq&#39;).val()=="") 
{ 
$(&#39;#qq&#39;).focus(); 
alert("手机号码不能为空!"); 
return false; 
} 
if($(&#39;#tel&#39;).val()=="") 
{ 
$(&#39;#tel&#39;).focus(); 
alert("所选产品不能为空!"); 
return false; 
} 
if($(&#39;#dizhi&#39;).val()=="") 
{ 
$(&#39;#dizhi&#39;).focus(); 
alert("地址不能为空!"); 
return false; 
} 
}) 
}); 
--> 
<input type=&#39;text&#39; name=&#39;ytel&#39; id=&#39;ytel&#39; style=&#39;width:250px&#39; class=&#39;intxt&#39; value=&#39;&#39; />*

Note: The part is the ID of your form (if not, please add it in the form) and the required ID.

The above is the detailed content of How to modify the required fields of custom form options in dedecms. 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