0

I want to display the entered fields from 2 drop down menus in another page.

Code:

<form action="home/show" method="post">
<p>Vendor:</p>
<select id="v" name="v">
    <% @vendors.each do |vendor| %>
        <option value=<%= vendor.id%>><%= vendor.name%></option>
    <% end %>
<select>

<p>Retailer:</p>
<select id="r" name="r">
    <% @retailers.each do |retailer| %>
        <option value=<%= retailer.id%>><%= retailer.name%></option>
    <% end %>
<select>

<input type="submit" value="Submit">
</form>

Display page:

Vendor: <?php echo $_POST["v"]; ?>
Retailer: <?php echo $_POST["r"]; ?>

The page loads but the fields are empty

Jackery Xu
  • 386
  • 2
  • 5
  • 19

2 Answers2

1

Use $_POST instead of $_GET, like this:

Vendor: <?php echo $_POST["v"]; ?>
Retailer: <?php echo $_POST["r"]; ?>

The variables are submitted as POST-variables, as indicated by the form's submit method (method="post"). And they should be, don't use GET to submit forms. Look here for more information.

Community
  • 1
  • 1
Rian Schmits
  • 3,096
  • 3
  • 28
  • 44
1

You have use method="post" on your form, but are using $_GET in your php, you need to use $_POST

Jakeii
  • 1,273
  • 9
  • 16