簡體   English   中英

選擇選項中網址后面的參數

[英]Parameter behind url from select option

我已經搜索了很長時間,但似乎在堆棧或其他任何站點上都找不到任何答案。 我想做的是將所選選項放在index.php?后面index.php? 所以看起來像index.php?%ordernumber% 我該怎么做?
對不起,如果我的問題格式不正確,對不起,英語不是我的母語。

<form class="form-horizontal" action="/logic/orders/werkplaats/index.php?id=" method="post">
<div class="styled-select">
    <label for="inputProductieorder">Productieorder</label>
    <select name="productieorder" id="inputProductieorder" class="form-control">
        <?php
        global $db;

        $smt = $db->prepare('SELECT productieorder FROM lo_productieorder');
        $smt->execute();
        $data = $smt->fetchAll();

        foreach ($data as $row): ?>
            <option><?= $row["productieorder"] ?></option>
        <?php endforeach ?>
    </select>
    <button type="submit" id="btnSubmit" class="btn btn-submit">Verder</button>
</div>

嘗試這個:

<option value="<?= $row["productieorder"] ?>"><?= $row["productieorder"] ?></option>

這將設置選項的值。 結果將類似於:index.php?productieorder = value

將表單的方法更改為GET然后從操作中刪除查詢字符串:

<form class="form-horizontal" action="/logic/orders/werkplaats/index.php" method="get">

現在將<select>的名稱設置為id 這將是查詢字符串中的關鍵字。

<select name="id" id="inputProductieorder" class="form-control">

最后,設置希望查詢字符串在每個<option>具有的值。

foreach ($data as $row): ?>
    <option value="<?= $row["productieorder"] ?>"><?= $row["productieorder"] ?></option>
<?php endforeach; ?>

我認為沒有必要將POST更改為GET 這可能會打開不必要的安全風險。 只要在索引頁上獲取POST數據,就可以了。

使用已有的內容,刪除“?id =“,然后在捕獲數據時使用
$ordernumber = $_POST["productieorder"];

如果要使用GET ,則可能需要這樣:
<option value="index.php?ordernumber=<?= $row["productieorder"] ?>"><?= $row["productieorder"] ?></option>

那應該給你:
<option value="index.php?ordernumber=VALUE">VALUE</option>

暫無
暫無

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

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