-2

这是我的 PHP 代码

我在代码部分的注释中提到的问题点

if(isset($_POST['submit']))
{
    if(isset($_POST['rdoption1']))
    {
        $var1 = $_POST["rdoption1"];
    }
    if(isset($_POST['rdoption2']))
    {
        $var2 = $_POST["rdoption2"];
    }
    if(!isset($_POST['rdoption1']))
    {
        $message = "Please select Option1";
    }
    elseif(!isset($_POST['rdoption2']))
    {
        $message = "Please select Option2";
    }
    elseif($_POST['rdoption2'] == "checkSetXY")
    {
        if($_POST["valXLocation"] == "")
        {
            $message = "You forget to enter X value.";
        }
        elseif($_POST["valYLocation"] == "")
        {
            $message = "You forget to enter Y value.";
        }
    } // till here all is good. I get all error messages if anything is left vacant or not clicked on radio button
    elseif(empty($_POST['txtoption3'])) //this is not working //the issue is if i select rdoption1  any option and rdoption2 checkDefault next code logic work.. but next code logic does not work when i click on the radio of checkSetXY and enter x and y values.. It simply does not execute code further..
    {
        $message = "Please enter your name.";
    }
                else
    {               
        //insert into db
                 }
       }

这是带有 PHP 回显的 html 表单在这里我收到消息应该在的地方,但在我选择checkSetXY值时没有

        <?php if(!empty($message)){ echo $message; } ?>

        <form id="form1" name="form1" method="post" action="form1.php">

          Space portion:
              <input type="radio" name="rdoption1" value="RJ"/>space 1
              <input type="radio" name="rdoption1" value="SM" />space 2


            Pixel Location
                <div class="formText">
                <input type="radio" name="rdoption2" value="checkSetXY"/> Specify Location
                    X: <input type="text" id="locField" name="valXLocation">  
                    Y: <input type="text" id="locField" name="valYLocation"> 
                <input type="radio" name="rdoption2" value="checkDefault"/>Default

                <input type="text" class="input" name="txtoption3">
                <input type="submit" name="submit" value="Submit"> 
           </form>

现在我很困惑为什么不elseif考虑txtoption3

有什么帮助吗?提前致谢

4

3 回答 3

3

那是行不通的,因为它将始终被设置。所以,使用empty();

elseif(empty($_POST['txtoption3'])) //this is not working

解释

您正在张贴表格input。当您发送它而不填写任何内容时,它只会发送此值。""

空字符串等于null或未设置。

此外,正如Peter Szymkowski所说,请查看fiddle

于 2013-02-09T12:51:23.860 回答
1

如果它们为空,则设置文本字段。您必须与empty($_POST['txtoption3']).

于 2013-02-09T12:52:48.337 回答
-1

这是 if($_POST['rdoption2'] == "checkSetXY") 的 else

我猜这是真的,所以它不会进入其他

于 2013-02-09T12:52:00.927 回答