PbootCMS网站内容标题重复检测!添加文章标题时,自动查询是否重复

主机推荐网 343 0

实现方法

一、html部分改造

文件路径:apps/admin/view/default/content/content.html

1.搜索【内容标题】,大致在195行,内容修改为:

<div class="layui-form-item">
    <label class="layui-form-label">内容标题   <span class="layui-text-red">*</span></label>
    <div class="layui-input-inline" style="width:80%;">
        <input type="text" name="title" id="title" required lay-verify="required" placeholder="请输入内容标题" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux" id="email_msg">*</div>
</div>

2.页面底部{include file='common/ueditor.html'}内容前增加如下代码:

<script>
$(document).ready(function() {
	$("input").blur(function() {
		var $parent = $(this).parent();
		$parent.find(".formtips").remove();
		if ($(this).is("#title")) {
			var title = this.value;
			if (title == "") {
				$("#email_msg").html("<span class='reg-error' style='display: inline;'>标题不能为空!</span>")
			} else {
				$.ajax({
					url:"admin.php?p=/Content/checktitle/",
					data:{
						"formcheck":'{$formcheck}',
						"mcode":{$get.mcode},
						"title":title,
					},
					type:"POST",
					dataType:"json",
					success:function (data) {
						if (data.data =="有重复") {
							$("#email_msg").html("<a style='color:red'>"+data.data+"</a>");
						}else {
							$("#email_msg").html("<span style='color:#08a600'>"+data.data+"</span>")
						}
					}
				})
			}
		}
	});
});
</script>

二、PHP部分改造

文件路径:apps/admin/controller/content/ContentController.php

页面中增加如下代码即可:

// 文章标题查重
public function checktitle()
{
    if ($_POST) {
        $title = post('title');
        $id = post('id');
        $mcode = post('mcode');
			
        if (!$mcode) {
            error('传递的模型编码参数有误,请核对后重试!');
        }
        $result = $this->model->findContentAll($mcode,$title);
        if($result){
            success('有重复', - 1);
        }else{
            success('正常', - 1);
        }
    }
}

至此,功能增加完成。只检测本模块下的内容标题,不跨模块检测。

发布评论 0条评论)

  • Refresh code

还木有评论哦,快来抢沙发吧~