如果选中了单选按钮,则提交到其他页面 [英] If radio button checked, then submit to different page

查看:71
本文介绍了如果选中了单选按钮,则提交到其他页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个:

<form method="post" id="kl" action="step2.php">

<input type="radio" name="rubrik" value="bussines"></input>
<input type="radio" name"rubrik" value="private"></input>

<input type="image" value="submit" src="/images/submit.png" alt="Submit" />

</form>

我basicaly想要的是:选中第二个单选按钮后,将表单提交到另一个文件step2a.php.我怎样才能做到这一点? jQuery,Javascript,PHP?

What i bassicaly want is: When the second radio button is checked, to submit the form to step2a.php, a different file. How can i do this? Jquery, Javascript, php?

推荐答案

您可以使用JavaScript进行此操作(绑定提交侦听器,该侦听器检查单选按钮的值,然后设置表单的action属性).在以下方面(在服务器端)做某事更简单,更可靠:

You could do this with JavaScript (bind a submit listener that checks the value of the radio button and then sets the action property of the form), but it would be simpler and more reliable to do something (server side) along the lines of:

<form ... action="step-selector.php">

<?php
    if (isset($_POST['rubrik']) && $_POST['rubrik'] == 'bussines') {
        include('step2.php');
    } elseif (isset($_POST['rubrik']) && $_POST['rubrik'] == 'private') {
         include('step2a.php');
    } else {
         include('error-state.php');
    }
 ?>

这篇关于如果选中了单选按钮,则提交到其他页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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