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 に答える