PHP在URL上显示搜索结果标题

我正在创建PHP搜索表单,已将搜索变量名称添加到html表单,但是当我搜索这样的URL显示时,例如http:// localhost / zblog / results / 1 /时,URL上没有显示标题,我想获得这样的URL http: //本地主机/ zblog /结果/ 1 / xxxxxx


这是我的代码


 <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>


慕田峪9158850
浏览 155回答 2
2回答

茅侃侃

您可以通过JavaScript中的键侦听器来执行此操作<script>var myUrl = "<?php echo $url; ?>results/1/";function updateAction(ele) {&nbsp; &nbsp; var txt = ele.value; //get the user input&nbsp; &nbsp; 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............"/>&nbsp; &nbsp;&nbsp;

倚天杖

您的表单是通过post方法提交的。您需要从中获取搜索查询$_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............"/>&nbsp; &nbsp;&nbsp;<input id="search-btn" value="search" type="submit"/></form>
打开App,查看更多内容
随时随地看视频慕课网APP