基于输入类型选择的表单操作 [英] Form action based on Input Type selection

查看:115
本文介绍了基于输入类型选择的表单操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在php页面index.php中创建一个表单。当页面被加载时,会创建以下表单:

I am creating a form in php on the page "index.php". When the page is loaded the following form is created:

if($_SERVER['REQUEST_METHOD']!='POST')
{
        echo '
        <form action="index.php" method="POST">
        <fieldset style="width: 700px;">
        <legend>Enter your search below</legend>
        <textarea rows="1" cols="80" name="query">
        </textarea>
        </fieldset>
        <p>
        <input type="radio" value="Non-Aggregated"> Non-Aggregated
        <input type="radio" value="Aggregated"> Aggregated 
        &nbsp;
        &nbsp;
        <input type="submit" value="Search">
        </p>
        </form>';   
}

当用户点击提交按钮时,会显示相应的内容: p>

When the user clicks the submit button, the appropriate content is displayed:

else
{
    if ($_POST['query'])
    {
        //content displayed after form submission
    }
}

回到

Going back to the form, note the radio options:

<input type="radio" value="Non-Aggregated"> Non-Aggregated
<input type="radio" value="Aggregated"> Aggregated

是否有条件可以放在if语句中以执行基于不同的操作关于是否从单选按钮中选择 非聚合 聚合 ;如果是的话,我会如何去做这件事?

Is there a condition that I can place in the if-statement to carry out a different action based on whether Non-Aggregated or Aggregated is selected from the radio buttons; and if so how would I go about doing this?

感谢您的帮助。

推荐答案

<input type="radio" name="aggr" value="Non-Aggregated"> Non-Aggregated
<input type="radio" name="aggr" value="Aggregated"> Aggregated

执行POST方法后,您可以使用PHP检查值:

After POST method is executed you can check values with PHP:

if($_POST['aggr']=='Aggregated'){
//DO STUFF
}
if($_POST['aggr']=='Non-Aggregated'){
//DO OTHER STUFF
}

换句话说,您可以设置名称,如

In other way, you can set names, like

<input type="radio" name="Non-Aggregated" value="Non-Aggregated"> Non-Aggregated
<input type="radio" name="Aggregated" value="Aggregated"> Aggregated

检查 isset

if(isset($_POST['Aggregated'])){
    //DO STUFF
}
if(isset($_POST['Non-Aggregated'])){
  //DO OTHER STUFF
}

这篇关于基于输入类型选择的表单操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆