-1

I found this topic:

How to get input field value using PHP

But it didn't help to me. I didn't have any form just this:

echo '<input required  type = "number" name = "db" value="1" /><br>';

And I want this input type value store in a variable if I hit a link it should send this checkbox data as well and open the href with these values.

Like ?buy=#product_id&quantity=#insert_value_here

Now it sends only the product_id and the quantity value is empty.

DeluxeD
  • 133
  • 1
  • 5
  • 19

1 Answers1

1

There is a form shown below that will submit to a url and it will add buy=#product_id&quantity=#insert_value_here so you can access those variables in php using. $_GET['buy'] and $_GET['quantity']

This is in the javascript console after submitting using the SO snippet: enter image description here

You'll need to do some validation to ensure the values are set and that they are the proper type of info. Also, post would be better than get, and using a nonce would help prevent unwanted multiple submissions...

<form action="http://www.google.com" method="get" name="add-to-cart">
  <select name="buy">
    <option value="1">Product One</option>
    <option value="2">Product Two</option>
    <option value="3">Product Three</option>
  </select>
  <input type="number" name="quantity" max="10" min="0" step="1" required />
  <input type="submit" value="Submit" />
</form>
JasonB
  • 6,243
  • 2
  • 17
  • 27