html表单代码部分,就提交按钮改成botton,,添加onclick事件
表单代码:
<form action="javascript:;" enctype="multipart/form-data" method="post">
<input type="hidden" name="action" value="post" />
<input type="hidden" name="diyid" value="1" />
<input type="hidden" name="do" value="2" />
<label>姓名:<input type="text" id="name" name="name" value="" /></label>
<label>电话:<input type="text" id="tel" name="tel" value="" /></label>
<label>手机:<input type="text" id="iphone" name="iphone" value="" /></label>
<label>邮箱:<input type="text" id="email" name="email" value="" /></label>
<table>
<tr>
<td valign="top">留言:</td>
<td><textarea id="liuyan" name="liuyan"></textarea></td>
</tr>
</table>
<input type="hidden" name="dede_fields" value="name,textchar;tel,textchar;iphone,textchar;email,textchar;liuyan,multitext" />
<input type="button" class="submit fr" value="提 交" οnclick="add_ajaxmessage()"/>
</form>
function add_ajaxmessage(){
var name=document.getElementById("name");
var tel =document.getElementById("tel");
var iphone=document.getElementById("iphone");
var email=document.getElementById("email");
var liuyan=document.getElementById("liuyan");
//定义变量接收上面表单每项的值和几个dede隐藏的input的值
var dataString = 'name='+ name.value + '&tel=' + tel.value + '&iphone=' + iphone.value + '&email=' + email.value + '&liuyan='+ liuyan.value +'&action=post'+ '&diyid=1&do=2&dede_fields=name,textchar;tel,textchar;iphone,textchar;email,textchar;liuyan,multitext';
$.ajax({
type: "POST",
url: "/plus/diy.php", //提交到后台文件
data: dataString, //传值
success: function(data) {
alert(data);//成功打印PHP返回的值
}
});
return false;
}
找到:if(!empty($dede_fields))
{
//在里面加入判断语句,不判断也可以
if($name==""){
echo "请填写您的姓名!";//注意:输出用echo输出,不要用showMsg();
exit();
}
}
找到:$goto = !empty($cfg_cmspath) ? $cfg_cmspath : '/';
$bkmsg = '发布成功,请等待管理员处理...';
这两句,改成:echo "提交成功!";
删掉下面这一句:showmsg($bkmsg, $goto);