3

我一直在尝试将表单中包含的一些信息发布给自己。但我不明白为什么它不起作用。当我从 HTML 页面发布数据时它可以工作,但是当我将信息发布到自身时它不起作用。

继承人的代码:

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

当我从 HTML 表单发布信息时,它工作正常,但在提交给自身时,所有变量都包含“on”的值。我不知道我遗漏了什么或未能正确实施。

这是 HTML 表单代码:

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

2 回答 2

6

您没有在表单中设置任何值。指向另一个页面时这是如何工作

<input id = 'c1' type= "radio" name= "country" checked value='mexico' />

您确实需要value='something'在表单中设置 a 以便传递正确的数据。您可能在传递表单元素时将它们设置为“打开”,但其中没有任何信息value

于 2012-08-19T03:50:36.343 回答
0

同意 Fluffeh 的观点。您的特定标签的“值”被转发到您的 PHP 代码。没有这些值,您将无法获得所需的结果。

<input id = 'c1' type= "radio" value="Mexico" name= "country" checked="checked" /> Mexico <br />
<input id = 'c2' type= "radio" value="Belize" name= "country" /> Belize <br />

在 PHP 中,这些值将被设置为国家。

于 2012-08-19T06:02:13.810 回答