我正在创建PHP搜索表单,我已将搜索变量名称添加到html表单,但当我搜索这样的http://localhost/zblog/results/1/的URL显示时却没有在URL上显示标题我想得到这样的URL http://localhost/zblog/results/1/xxxxxx < / p>
这是我的代码
<form action="<?php echo $url; ?>results/1/<?php $search;?>" method="post" name="search" id="searchthis" style="display:inline;">
<input id="search-box" name="search" size="40" type="text" placeholder="what are you looking for............"/>
<input id="search-btn" value="search" type="submit"/>
</form>
答案 0 :(得分:0)
您的表格是通过邮寄方式提交的。您需要从$_POST['search']
获取搜索查询,并将其分配给变量$search
<?php $search = $_POST['search'] ?>
<form action="<?php echo $url; ?>results/1/<?php $search;?>" method="post" name="search" id="searchthis" style="display:inline;">
<input id="search-box" name="search" size="40" type="text" placeholder="what are you looking for............"/>
<input id="search-btn" value="search" type="submit"/>
</form>
答案 1 :(得分:0)
您可以通过JavaScript中的键侦听器完成此操作
<script>
var myUrl = "<?php echo $url; ?>results/1/";
function updateAction(ele) {
var txt = ele.value; //get the user input
ele.parentElement.setAttribute("action",myUrl+txt);
}
</script>
<input onkeyup="updateAction(this);" id="search-box" name="search" size="40" type="text" placeholder="what are you looking for............"/>