Dvbbs发贴时验证文件是否上传

在Dvbbs中发贴时,文件的上传和贴子的发布是分开进行的(先传文件再发贴),这导致一些用户在发贴时文件选择了却没有上传,下边我们来修改下Js函数,在发贴前先验证下文件域是否为空,如果不为空则提示用户文件还未上传。

修改1:针对发贴和完整的回复模式。

打开"images/post/DhtmlEdit1.js"修改Checkpostdata函数(红色部分新增):

String.prototype.Trim=function(){return this.replace(/(^\s*)|(\s*$)/g,"");}
function Checkpostdata(theform)
{
    //检测文件是否上传
    try{
        if(frames["ad"].document.forms["form"].file1)
        {
            if((frames["ad"].document.forms["form"].file1.value).Trim() != "")
            {
                if(! confirm("文件还没有上传,确定不传吗?"))
                {
                    frames["ad"].document.forms["form"].file1.focus();
                    return false;
                }
            }
        }
    }
    catch(e){}

    
    Dvbbs_CopyData('Body');
    Checkdata();
    if (ischeck==false)
    {
        return false;
    }
    else{
        try{
            if (typeof(ajaxpost) != "undefined")
                return ajaxpost.postForm(theform);
            else
                return true;
        }
        catch (e){return true;}        
    }
}

修改2:针对快速回复模式。登录后台"风格模板管理→分页面模板(dispbbs)→界面风格管理→template.html(0)",找到Js的Checkpostdata函数修改如下(红色部分新增):

String.prototype.Trim=function(){return this.replace(/(^\s*)|(\s*$)/g,"");}
function Checkpostdata(theform){
    //检测文件是否上传
    try{
        if(frames["ad"].document.forms["form"].file1)
        {
            if((frames["ad"].document.forms["form"].file1.value).Trim() != "")
            {
                if(! confirm("文件还没有上传,确定不传吗?"))
                {
                    frames["ad"].document.forms["form"].file1.focus();
                    return false;
                }
            }
        }
    }
    catch(e){}


    Dvbbs_CopyData('Body');
    var Dvbbs_bIsIE5=document.all;
    var Dvbbs_Mode = 0;
    if (Dvbbs_bIsIE5){
        var IframeID=frames["Dvbbs_Composition"];
    }
    else{
        var IframeID=document.getElementById("Dvbbs_Composition").contentWindow;
        var Dvbbs_bIsNC=true;
    }

    if (theform.codestr!=null){
        if (theform.codestr.value==''){
            document.getElementById('errinfo').innerHTML='<li><font color="red">你忘记输入验证码了!</font></li>';
            theform.codestr.focus();
            return false;
        }
    }
    if (theform.Body.value.length==0){
        document.getElementById('errinfo').innerHTML='<li><font color="red">你忘记填写回复内容了!</font></li>';
        IframeID.focus();
        return false;
    }else{
        if (theform.Body.value.length <xsl:value-of select="'>'" disable-output-escaping="yes"/> <xsl:value-of select="post/setting/@maxpostlen"/>) {
            document.getElementById('errinfo').innerHTML='<li><font color="red">回复内容不能大于 <xsl:value-of select="post/setting/@maxpostlen"/> 字节!</font></li>';
            IframeID.focus();
            return false;
        }

        if (theform.Body.value.length <xsl:value-of select="'<'" disable-output-escaping="yes"/> <xsl:value-of select="post/setting/@leastpostlen"/>) {
            document.getElementById('errinfo').innerHTML='<li><font color="red">回复内容不能小于 <xsl:value-of select="post/setting/@leastpostlen"/> 字节!</font></li>';
            IframeID.focus();
            return false;
        }
    }
    return ajaxpost.postForm(theform);
}

上边代码在Dvbbs8.1.1中检测通过!

评论: 0 | 引用: 0 | 查看次数: 5100
发表评论
登录后再发表评论!