1

Не получается отправить get запрос. Надо выбрать один из тре ценноков или ввести свою цену и отправить это методом get, пока что просто в адресную сртоку.

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

Ввести пятаюсь так

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

В чем проблема?

1
  • 1
    $_GET['price']; - это переменная, вы ее не выводите. Вывести можно через echo $_GET['price']; 23 окт 2018 в 3:32

2 ответа 2

2

Для автоматической отсылки формы по нажатию кнопки:

<input type="submit" ...

вместо

<input type="button" ...

Имейте в виду, что если будет нажата последняя кнопка, значения с ключом 'price' в запросе не будет.

Или так - с радио-кнопками вместо обычных кнопок:

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

3
  • Я понял свою ошибку, но вопрос остается. Как выбраненую или введеную сумма отправить get запросом?
    – MegaRoks
    23 окт 2018 в 3:39
  • @MegaRoks Поставьте type="submit" всем кнопкам.
    – user176262
    23 окт 2018 в 3:40
  • Но тогда посто по нажатии будет отправляться, как сдеалт ьчтобы пользовательно выбрал или ввел цену, а потом нажал на price_btn и только тогда отправился запрос
    – MegaRoks
    23 окт 2018 в 3:44
0

Две формы. В одной человек может выбрать цену, во второй ввести свое значение.

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

Вариант с выбором

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

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.