Can not send get request. You must select one of the treasures or enter your price and send it using the get method, for now just to the address field.

<form action="" method="get"> <fieldset> <input type="button" name="price" value="500р"> <input type="button" name="price" value="1000р"> <input type="button" name="price" value="5000р"> <input type="text" name="other_price" placeholder="Своя цена"> <input type="submit" name="price_btn"> </fieldset> </form> 

Enter back down

 <?php $_GET['price']; ?> 

What is the problem?

  • one
    $_GET['price']; - this is a variable, you do not display it. You can display it via echo $_GET['price']; - Mr Lucky Tomas

2 answers 2

To automatically submit a form at the click of a button:

 <input type="submit" ... 

instead

 <input type="button" ... 

Keep in mind that if the last button is pressed, there will be no value with the 'price' key in the request.

Or so - with radio buttons instead of the usual buttons:

 // this script is here only to demonstrate submitted form data $("form").submit(function(e) { console.log($(this).serialize()); return false; }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form action="" method="get"> <fieldset> <label><input type="radio" name="price" value="500р">500р</label><br/> <label><input type="radio" name="price" value="1000р">1000р</label><br/> <label><input type="radio" name="price" value="5000р">5000р</label><br/> <label><input type="radio" name="price" value="custom">Своя цена</label><br/> <input type="text" name="custom_price" placeholder="Своя цена"> <input type="submit" name="price_btn"> </fieldset> </form> 

  • I understood my mistake, but the question remains. How to send the selected or entered amount by request? - MegaRoks
  • @MegaRoks Put type="submit" all buttons. - Igor
  • But then it will be sent by clicking on it, as it was done by the user to select or enter the price, and then clicked on price_btn and only then the request was sent - MegaRoks

Two forms. In one person can choose the price, in the second enter your value.

 <h3>По нажатию выбранной цены, просто две формы</h3> <form action="" method="get"> <fieldset> <input type="submit" name="price" value="500р"> <input type="submit" name="price" value="1000р"> <input type="submit" name="price" value="5000р"> </fieldset> </form> <form action="" method="get"> <fieldset> <input type="text" name="custom_price" placeholder="Своя цена"> <input type="submit" name="price_btn"> </fieldset> </form> 

Choice option

 <h3>Выбор из цен</h3> <form action="" method="get"> <fieldset> <label><input type="radio" name="price" value="500"> 500р</label> <label><input type="radio" name="price" value="1000"> 1000р</label> <label><input type="radio" name="price" value="5000"> 5000р</label> <input type="text" name="other_price" placeholder="Своя цена"> <input type="submit" name="price_btn"> </fieldset> </form>