好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

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

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

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

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

//增加必填字段判断   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、保存完成后,在表单页面找到这行代码.

<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的内容为:

<!--  $(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= ''  />* 

注:部分为你表单的ID(如果没有请在表单里面添加上)和必填ID.

查看更多关于dedecms织梦自定义表单选项必填如何修改解决办法的详细内容...

  阅读:47次