木子屋 Dnawo's BLOG

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

👤 dnawo 📅 2008-01-18 👁 6007 👍 0 💬 0 🔄 本站原创
在Dvbbs中发贴时,文件的上传和贴子的发布是分开进行的(先传文件再发贴),这导致一些用户在发贴时文件选择了却没有上传,下边我们来修改下Js函数,在发贴前先验证下文件域是否为空,如果不为空则提示用户文件还未上传。

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

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

[color=Red]String.prototype.Trim=function(){return this.replace(/(^\s*)|(\s*$)/g,"");}[/color]
function Checkpostdata(theform)
{
	[color=Red]//检测文件是否上传
	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){}[/color]
	
	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函数修改如下(红色部分新增):

[color=Red]String.prototype.Trim=function(){return this.replace(/(^\s*)|(\s*$)/g,"");}[/color]
function Checkpostdata(theform){
	[color=Red]//检测文件是否上传
	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){}[/color]

	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)

暂无评论。

计算题
评论需审核通过后显示
← 上一篇 ASP也支持With语句 下一篇 → Dvbbs上传头像提示"您已经上传了头像"解决方法