在php脚本中包含html表单

时间:2016-06-21 13:54:40

标签: php html

我正在尝试创建一个包含HTML表单的PHP脚本。请帮我编辑一下:

$SoapClient = new SoapClient ( NULL, $options );
try {
    $cities = $SoapClient->getCities ();
    // echo var_dump($SoapClient->getCities ());

    echo "<form action= " . "'$" . "PHP_SELF' method = 'post'>";
    echo "<h4>Choose Origin</h4>";

    foreach ( $cities as $city ) {
        echo "<input type='radio'    name = 'origin' value = " . $city . "> <br>";
    }

    echo "<h4>Choose Destination</h4>";

    foreach ( $cities as $city ) {
        echo "<input type='radio'    name = 'destination' value = " . $city . "> <br>";
    }
    echo "<p>";
    echo "<input type='submit' name='submitButton' value='Calculate Great Circle'>";
    // show soap request and response
} catch ( Exception $e ) {
    echo "<h3>SOAP error</h3><pre>" . $e . "</pre>";
    echo "<h3>SOAP error last response</h3><pre>" . $SoapClient->__getLastResponse () . "</pre>";
    echo "<h3>SOAP error last request</h3><pre>" . $SoapClient->__getLastRequest () . "</pre>";
}

非常感谢:)

1 个答案:

答案 0 :(得分:1)

您想要显示无线电旁边的城市名称,请在两个循环中尝试:

foreach ( $cities as $city ) {
    echo "<label><input type='radio' name='origin' value='" . $city . "'>" . $city . "</label> <br>";
}

并替换

echo "<form action= " . "'$" . "PHP_SELF' method = 'post'>"; 

通过

echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="post">';