簡體   English   中英

PHP / HTML表單操作屬性

[英]PHP/HTML form-action attribute

我有一個小問題。 我有一種表格,可以搜索。 提交此表格后不能停留在同一頁面上。

我的網址:

www.localhost / index.php?vehicletype = car

在此網址上,汽車搜索可見。

提交后,我得到以下信息:

本地主機/index.php?body_type=any&fuel_type .....

但是我想要這個

www.localhost / index.php?vehicletype = car?body_type = any&fuel_type ....

我嘗試了$_SERVER["REQUEST_URI"]但是什么也沒有。 感謝您的幫助,也很抱歉我的英語語法!

編輯:代碼:

 <? if($_GET['vehicletype']=='car'){ ?> <div class="search"> <form method="get" action=""> .... <button class="btn btn-search" type="submit">Search <hr> (658 found)</button> </form> </div> 

網址后面的第一件事是錯誤的“ www.localhost / index.php?vehicletype = car?body_type = any&fuel_type ....”

在“?”之后 它將在get方法中設置所有參數,您可以使用$ _GET ['variablename']訪問該變量

如果您想在同一頁面上,可以按照以下方式進行操作

<form action="#" method="GET">

當某人單擊提交按鈕時,將使用表單參數調用同一頁面。

您可以使用$ _GET方法獲取所有表單參數。

方法1

<?php
if(isset($_GET['vehicletype']) && $_GET['vehicletype'] == 'car')
{
       //write business login that you want to show once search action perform by user
}
else
{
?>

Show HTML Form here 

<?php } ?>

方法2

<?php
    if(isset($_GET['vehicletype']) && $_GET['vehicletype'] == 'car')
    {
           //write business login that you want to show once search action perform by user
    }

<form action="#" method="GET">
<input type="text" name="vehicletype" value="<?php if (isset($_GET['vehicletype'])) { echo $_GET['vehicaletype']; } ?>">
</form>

讓我知道您是否還有進一步的查詢。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM