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='{dede:global.cfg_templets_skin/}/style/js/js.js' type="text/javascript">
The content of this js is:
The code is as follows :
<!-- $(document).ready(function() { //验证 $('#complain').submit(function () { if($('#yname').val()==""){ $('#yname').focus(); alert("姓名不能为空!"); return false; } if($('#qq').val()=="") { $('#qq').focus(); alert("手机号码不能为空!"); return false; } if($('#tel').val()=="") { $('#tel').focus(); alert("所选产品不能为空!"); return false; } if($('#dizhi').val()=="") { $('#dizhi').focus(); alert("地址不能为空!"); return false; } }) }); --> <input type='text' name='ytel' id='ytel' style='width:250px' class='intxt' value='' />*
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!