当前位置:首页 > CMS教程 > DeDecms > 列表

dedecms织梦自定义表单选项必填如何修改解决办法

发布:smiling 来源: PHP粉丝网  添加日期:2014-11-03 20:19:31 浏览: 评论:0 

方法一:我当时测试的时候没成功,首先我们要用一段php代码来判断验证必选项.

1、我们先在plus/diy.php 文件中的的第40行下加上一下代码:

  1. //增加必填字段判断 
  2. if($required!=''){ 
  3.  
  4. if(preg_match('/,/', $required)) 
  5.     { 
  6.         $requireds = explode(',',$required); 
  7.         foreach($requireds as $field){ 
  8.             if($$field==''){ 
  9.                 showMsg('带*号的为必填内容,请正确填写', '-1'); 
  10.                 exit();  //phpfensi.com 
  11.             } 
  12.         } 
  13.     }else{ 
  14.         if($required==''){ 
  15.             showMsg('带*号的为必填内容,请正确填写', '-1'); 
  16.             exit(); 
  17.         } 
  18.     } 
  19. } 
  20. //end 

2、保存完成后,在表单页面找到这行代码.

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

在这行代码之下,加入代码:

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

方法二:我最终以另外的方式,实现了,在你的表单页面加上一个JQ和一个JS:

<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js">

<script src='{dede:global.cfg_templets_skin/}/style/js/js.js' type="text/javascript">;

这个js的内容为:

  1. <!-- 
  2. $(document).ready(function() 
  3. { 
  4. //验证 
  5. $('#complain').submit(function () 
  6. { 
  7. if($('#yname').val()==""){ 
  8. $('#yname').focus(); 
  9. alert("姓名不能为空!"); 
  10. return false; 
  11. } 
  12. if($('#qq').val()=="") 
  13. { 
  14. $('#qq').focus(); 
  15. alert("手机号码不能为空!"); 
  16. return false; 
  17. } 
  18. if($('#tel').val()=="") 
  19. { 
  20. $('#tel').focus(); 
  21. alert("所选产品不能为空!"); 
  22. return false; 
  23. } 
  24. if($('#dizhi').val()=="") 
  25. { 
  26. $('#dizhi').focus(); 
  27. alert("地址不能为空!"); 
  28. return false; 
  29. } 
  30. }) 
  31.  
  32. }); 
  33. --> 
  34.  
  35.  <input type='text' name='ytel' id='ytel' style='width:250px'  class='intxt' value='' />* 
注:部分为你表单的ID(如果没有请在表单里面添加上)和必填ID.

Tags: dedecms自定表单 dedecms表单选项

分享到: