1

这是一个显示创意列表的页面,该表单提供了按职位搜索的搜索功能:

 if(isset($_POST['creatives-submit'])){
    $job = $_POST['job-title'];
    $data = \Db::Common($fms5->DBH)->getWhere("creatives", "creatives_active", "Yes"," AND creatives_job LIKE '%".$job."%'")->orderBy('creatives_name', 'asc');
}

<form method="post" name="creative-search">
	<input class="form-control" type="textbox" name="job-title" id="job-title" placeholder="Search by job title" />
	<input class="form-control" type="submit" name="creatives-submit" id="creatives-submit" style="display: none;" />
</form>

我的代码有什么明显错误的吗?

4

1 回答 1

-2

尝试更改 if(isset($_POST['creatives-submit']))if(isset($_POST['job-title']) && !empty($_POST["job-title"])),因为表单正在发布job-title值,这是您真正关心的值。(因为creatives-submit将永远 = Submit

也改变 <input class="form-control" type="textbox" name="job-title" id="job-title" placeholder="Search by job title" />

<input class="form-control" type="text" name="job-title" id="job-title" placeholder="Search by job title" required/>

job-title这意味着除非该字段具有值并且具有正确的类型,否则无法提交表单text

下面是您的代码的修改,它只返回用户搜索的内容(因为我没有将它连接到数据库)

<?php
 if(isset($_POST['job-title']) && !empty($_POST["job-title"])){
    $job = $_POST['job-title'];
    ?>
    <p>You Searched For <?php echo $job;?></p>
<?php   
}
?>

和形式

<!-- Search Form -->
<form method="post" name="creative-search">
    <input class="form-control" required="required" type="text" name="job-title" id="job-title" placeholder="Search by job title" />
    <input class="form-control" type="submit" name="creatives-submit" id="creatives-submit" style="display: none;" />
</form>
于 2020-01-10T13:53:04.033 回答