【问题标题】:I need a yes and no button in my form. If the information is correct and yes is clicked thanks should appear我的表单中需要一个是和否按钮。如果信息正确并且单击是,应该出现谢谢
【发布时间】:2016-03-29 22:16:36
【问题描述】:

我不知道如何在我的表单中添加“是”和“否”按钮,以便当用户插入并按下提交按钮时,数据会从服务器端脚本发回并返回给用户,然后用户单击是或否按钮来批准信息。如果是,程序应该提出异议,谢谢

<html>
        <head>
            <title>Test1-1</title>
        </head>
        <body>
    <?php

    if (filter_has_var(INPUT_POST, "name")){

    $name = filter_input(INPUT_POST, "name");
    print "<p>Hi $name, </p>";
    }

    if (filter_has_var(INPUT_POST, "id")){

    $id = filter_input(INPUT_POST, "id");
    print "<span>Your Employee ID is $id</span>";
    }

    if (filter_has_var(INPUT_POST, "office")){

    $office = filter_input(INPUT_POST, "office");
    print "<span>, your office is room $office</span>";
    }

    if (filter_has_var(INPUT_POST, "os")){

    $os = filter_input(INPUT_POST, "os");
    print "<span>, and your OS is $os</span>";
    }

     else {


    //there's no input. Create the form 
    print <<< HERE

    <form action ="" method = "post">
    <fieldset>
    <label>Enter your name</label> 
    <input type = "text"
             name = "name"/><br>
    <label>Employee ID</label> 
    <input type = "text"
             name = "id"/><br>
    <label>Office Room Number</label> 
    <input type = "text"
             name = "office"/><br>
    <label>Oberating System on the Office Computer</label> 
    <input type = "text"
             name = "os"/><br>
    <button type = "submit">
     submit
    </button>
    </fieldset> 
    </form>
    HERE;
    }// end 'value exists' if
    ?>
        </body>
    </html>

【问题讨论】:

  • 您可能会想要使用 ajax,这样您就可以将表单数据发送到服务器端代码,然后当它返回时更新 html,以便用户看到是/否按钮。从那里你将需要更多的 ajax 代码来处理当他们点击是/否时发生的事情。

标签: php forms button


【解决方案1】:

如果您只是想要一个是或否按钮,那么您只需要简单的 html &lt;input type="button" value="YES"&gt; &lt;input type="button" value="NO"&gt;

【讨论】:

    猜你喜欢
    • 2017-12-18
    • 2017-04-05
    • 1970-01-01
    • 1970-01-01
    • 2012-08-09
    • 2021-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多