dedecms织梦自定义表单选项必填如何修改解决办法
发布:smiling 来源: PHP粉丝网 添加日期:2014-11-03 20:19:31 浏览: 评论:0
方法一:我当时测试的时候没成功,首先我们要用一段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.
Tags: dedecms自定表单 dedecms表单选项
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
 - PHP新手上路(一)(7)
 - 惹恼程序员的十件事(5)
 - PHP邮件发送例子,已测试成功(5)
 - 致初学者:PHP比ASP优秀的七个理由(4)
 - PHP会被淘汰吗?(4)
 - PHP新手上路(四)(4)
 - 如何去学习PHP?(2)
 - 简单入门级php分页代码(2)
 - php中邮箱email 电话等格式的验证(2)
 
