1、在模板下发加上如下代码
<script> $("#table-search-tool-submit").click(function(e) { // 阻止表单的默认提交行为 e.preventDefault(); const keywordValue = $('[name="keyword"]').val(); if(!keywordValue){ layer.msg("请输入搜索的关键词"); return false; } // 获取按钮所在的表单元素 const form = $(this).closest('form'); // 获取表单的action属性 const actionUrl = form.attr('action'); // 获取表单数据 const formData = form.serialize(); // 构建带查询参数的URL const redirectUrl = actionUrl + '?' + formData; // 页面跳转 window.location.href = redirectUrl; }); </script>
第二步,在对应的PHP代码 index改成如下
// 查看列表 public function index() { $field=dr_safe_replace(\Phpcmf\Service::L('input')->get('field')); // 会进行xss安全过滤 if($field){ $keyword=dr_safe_replace(\Phpcmf\Service::L('input')->get('keyword')); // 会进行xss安全过滤 $where = "$field like '%".$keyword."%'"; if ($this->init['where_list']) { $this->init['where_list'].= " AND ".$where; } else { $this->init['where_list'] = $where; } } list($tpl) = $this->_List(); \Phpcmf\Service::V()->display($tpl); }