织梦自定义表单验证字段不能为空,绝对实用灵活

来源:互联网 发布:思归软件下载 编辑:程序博客网 时间:2024/06/05 09:17

织梦自定义表单验证字段不能为空,不是通过前台页面js验证,绝对灵活实用。


模板文件的修改:

1、修改diy_field_add.htm,23行左右添加代码

var necessary = theform.necessary[0].checked?theform.necessary[0].value:theform.necessary[1].value;

替换字符串,大概在38行

替换revalue =  "<field:"+fieldname+" itemname=\""+itemname+"\" autofield=\"1\" type=\""+dtype+"\" isnull=\""+sisnull+"\" default=\""+vdefault+"\" ";

为revalue =  "<field:"+fieldname+" itemname=\""+itemname+"\" autofield=\"1\" type=\""+dtype+"\" isnull=\""+sisnull+"\" necessary=\""+necessary+"\" default=\""+vdefault+"\" ";


2、diy_field_add.htm,大概124行</tr>后面,添加代码

    <tr> 

      <td bgcolor="#FFFFFF">

      <strong>是否为必填项:</strong><br/>

      <span class="STYLE2">防止恶意提交表单</span>

      </td>

      <td bgcolor="#FFFFFF">

        <input name="necessary" type="radio"  value="true" class='np' checked='1' />

         是

         &nbsp; 

        <input name="necessary" type="radio"  value="false" class='np' />

         否

     </td>

    </tr>


3、修改diy_field_edit.htm,18行左右添加代码

var necessary = theform.necessary[0].checked?theform.necessary[0].value:theform.necessary[1].value;

替换字符串,大概在38行

替换revalue += " isnull=\""+sisnull+"\" default=\""+vdefault+"\" ";

为revalue += " isnull=\""+sisnull+"\" necessary=\""+necessary+"\" default=\""+vdefault+"\" ";


4、diy_field_edit.htm,大概139行</tr>后面添加代码

<tr> 

      <td bgcolor="#FFFFFF"><strong>是否为必填项:</strong><br/>

        <span class="STYLE2">防止恶意提交表单</span></td>

      <td bgcolor="#FFFFFF">

        <input name="necessary" type="radio"  value="true"<?PHP  if($ctag->GetAtt('necessary')=='true') echo " checked='1' "; ?> class='np' />

        是 &nbsp; 

        <input name="necessary" type="radio"  value="false"<?php  if($ctag->GetAtt('necessary')=='false'||$ctag->GetAtt('necessary')=='') echo " checked='1' "; ?> class='np' />

        否  </td>

      </tr>


5、表单提交处理:

修改plus/diy.php文件

找到$addvar = $addvalue = '';在上面添加代码


        //验证必填字段

        $row = $dsql->GetOne("SELECT * FROM `#@__diyforms` WHERE `table`='{$diy->table}'");

        $fieldset = $row['info'];

        require_once(DEDEINC."/dedetag.class.php");

        $dtp = new DedeTagParse();

        $dtp->SetNameSpace("field","<",">");

        $dtp->LoadSource($fieldset);

        if(is_array($dtp->CTags))

        {

            foreach($dtp->CTags as $tagid=>$ctag)

            {

                if($ctag->GetAttribute("necessary")=='true' && empty(${$ctag->GetName()}))

                {

                     showmsg($ctag->GetAttribute("itemname")."不能为空!", -1);

                     exit;

                }

            }

        }

6、这样基本就搞定了,设置参数请通过后台字段编辑设置



文章来源:http://blog.csdn.net/taohaoge/article/details/16963537


http://www.456sou.cn/duanzi/256.htmlhttp://www.456sou.cn/duanzi/257.htmlhttp://www.456sou.cn/duanzi/258.htmlhttp://www.456sou.cn/duanzi/259.htmlhttp://www.456sou.cn/duanzi/260.htmlhttp://www.456sou.cn/lizhi/lizhiwenzhang/261.htmlhttp://www.456sou.cn/lizhi/lizhiwenzhang/262.htmlhttp://www.456sou.cn/lizhi/lizhigushi/263.htmlhttp://www.456sou.cn/lizhi/lizhigushi/264.htmlhttp://www.456sou.cn/lizhi/renshengganwu/244.htmlhttp://www.456sou.cn/xiaohua/245.htmlhttp://www.456sou.cn/xiaohua/246.htmlhttp://www.456sou.cn/xiaohua/247.htmlhttp://www.456sou.cn/duanzi/248.htmlhttp://www.456sou.cn/duanzi/249.htmlhttp://www.456sou.cn/duanzi/250.htmlhttp://www.456sou.cn/xiaohua/251.htmlhttp://www.456sou.cn/xiaohua/252.htmlhttp://www.456sou.cn/xiaohua/253.htmlhttp://www.456sou.cn/xiaohua/254.htmlhttp://www.456sou.cn/xiaohua/255.htmlhttp://www.456sou.cnhttp://www.456sou.cn/xiaohuahttp://www.456sou.cn/tupianhttp://www.456sou.cn/duanzihttp://www.456sou.cn/GIFhttp://www.456sou.cn/lizhihttp://www.456sou.cn/lizhi/lizhiwenzhanghttp://www.456sou.cn/lizhi/lizhigushihttp://www.456sou.cn/lizhi/lizhimingyanhttp://www.456sou.cn/lizhi/renshengganwuhttp://www.456sou.cn/lizhi/jingdianyuluhttp://www.456sou.cn/lizhi/zhichanglizhihttp://www.456sou.cn/lizhi/qingchunlizhihttp://www.456sou.cn/lizhi/weirenchushihttp://www.456sou.cn/lizhi/jingdianmeiwenhttp://www.456sou.cn/lizhi/lizhikouhaohttp://www.456sou.cn/lizhi/chenggonglizhihttp://www.456sou.cn/lizhi/jingdianjuzihttp://www.456sou.cn/lizhi/lizhichuangyehttp://www.456sou.cn/lizhi/shangganrizhi
0 0
原创粉丝点击