Yuki Kutsuya
Yuki Kutsuya

Reputation: 4088

Parameter behind url from select option

I can't seem to find any answer on stack or any other site, I've searched for quite some time. What I'm trying to do is to put the selected option behind the index.php? so it will look like index.php?%ordernumber%. How can I accomplish this?
Sorry if my question isn't formatted right, English isn't my native language, sorry.

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

Upvotes: 1

Views: 68

Answers (3)

Pixel Rubble
Pixel Rubble

Reputation: 1101

I don't think changing POST to GET is necessary. That could open up security risks that aren't needed. As long as you're getting the POST data on the index page, you should be fine.

using what you're already have, remove the "?id=", then when capturing the data, use
$ordernumber = $_POST["productieorder"];

If you want to use GET, what you may need is this:
<option value="index.php?ordernumber=<?= $row["productieorder"] ?>"><?= $row["productieorder"] ?></option>

That should give you:
<option value="index.php?ordernumber=VALUE">VALUE</option>

Upvotes: 0

Peter Gordon
Peter Gordon

Reputation: 1077

Change the form's method to GET and remove the query string from the action:

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

Now set the <select>'s name to id. This will be the key in the query string.

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

Finally, set the value you want the query string to have in each <option>.

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

Upvotes: 2

Johan
Johan

Reputation: 929

Try this:

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

This will set the value of the option. And the result will be something like : index.php?productieorder=value

Upvotes: 2

Related Questions