I have been trying to post some information contained in a form to itself. But I dont understand why its not working. It works when I post the data from a HTML page but when i post the information to itself it doesnt work.
Heres the code:
$country = isset($_POST['country']) ? $_POST['country'] : 'Belize';
$number_of_guests = isset($_POST['number_of_guests']) ? $_POST['number_of_guests'] : 2;
$from = isset($_POST['price_range_from']) ? $_POST['price_range_from'] : 200;
$to = isset($_POST['price_range_to']) ? $_POST['price_range_to'] : 2000;
When I post the information from the HTML form it works fine but on submitting to itself all the variables contain the value of "on". I dont know what I am missing or failing to implement correctly.
Here is the HTML form code:
<form action="find_results.php" method = "post">
<strong>Select the Country</strong><br />
<input id = 'c1' type= "radio" name= "country" checked/> Mexico <br />
<input id = 'c2' type= "radio" name= "country" /> Belize <br />
<input id = 'c3' type = "radio" name= "country" />Jamaica <br />
<input id = 'c4' type = "radio" name= "country" />Thailand <br />
<input id = 'c5' type = "radio" name= "country" />Turks & Caicos
<hr />
<strong>Number of Guests</strong><br />
<input id = 'n1' type= "radio" name= "number_of_guests" /> 2
<input id = 'n2' type= "radio" name= "number_of_guests" /> 4
<input id = 'n3' type= "radio" name= "number_of_guests" /> 6
<input id = 'n4' type= "radio" name= "number_of_guests" /> 8
<input id = 'n5' type= "radio" name= "number_of_guests" /> 10+
<hr />
<strong>Price Range(From)</strong><br />
<input id = 'from1' type= "radio" name= "price_range_from" /> 200
<input id = 'from2' type= "radio" name= "price_range_from" /> 300
<input id = 'from3' type= "radio" name= "price_range_from" /> 400
<input id = 'from4' type= "radio" name= "price_range_from" /> 500
<input id = 'from5' type= "radio" name= "price_range_from" /> 600 or More
<hr />
<strong>Price Range(Upto)</strong><br />
<input id = 'to1' type= "radio" name= "price_range_to" /> 500
<input id = 'to2' type= "radio" name= "price_range_to" /> 600
<input id = 'to3' type= "radio" name= "price_range_to" /> 700
<input id = 'to4' type= "radio" name= "price_range_to" /> 800
<input id = 'to5' type= "radio" name= "price_range_to" /> 900 or More
<br />
<input type="submit" value="Submit" name='submit' />
</form>
You have no values set in the form. How does this work when pointing to another page?
<input id = 'c1' type= "radio" name= "country" checked value='mexico' />
You do need to set a value='something' in the form so that the right data is passed. You are probably getting them as 'on' as the form element is being passed, but with no information in the value of it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With