php重定向使用表单

1 html php forms

我查看堆栈的答案没有成功.我希望用单选按钮制作一个表单.根据选中的单选按钮,按提交按钮将指向您不同的页面.现在我使用带有get选项的php.然而,最好的办法是根据获取信息制作动态页面.任何帮助都会很棒

谢谢

Ale*_*s G 6

在您的PHP中,您可以检查$_GET['radio_option']并基于使用header函数重定向到其他页面的值,如下所示:

switch($_GET['radio_option']) {
case 'val1':
    header('location: page1.php');
    exit;
case 'val2':
    header('location: page2.php');
    exit;
case 'val3':
    header('location: page3.php');
    exit;
}

//here handle everything else - although normally you shouldn't get here
Run Code Online (Sandbox Code Playgroud)

另一种方法是使用javascript action在提交之前设置表单的属性.例如:

$(document).ready(function() {
    $("input:radio[name=your_radio_naem]").click(function() {
        var value = $(this).val();
        var target = "main.php";

        if(value == 'val1')
            target = "page1.php";
        else if(value == 'val2')
            target = "page2.php";
        else if(value == 'val3')
            target = "page3.php";

        $('#myform').attr('action', target);
    });
});
Run Code Online (Sandbox Code Playgroud)