来自select选项的url后面的参数

时间:2016-06-16 14:33:41

标签: php html parameters

我似乎无法在堆栈或任何其他网站上找到任何答案,我已经搜索了很长时间。我要做的是将所选选项置于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>

3 个答案:

答案 0 :(得分:2)

试试这个:

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

这将设置选项的值。结果将是这样的: 的index.php?productieorder =值

答案 1 :(得分:2)

将表单的方法更改为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; ?>

答案 2 :(得分:0)

我认为不必将 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>