Javascript 如何根据所选的单选值从表单提交重定向到不同的URL

Javascript 如何根据所选的单选值从表单提交重定向到不同的URL,javascript,php,forms,Javascript,Php,Forms,我正在尝试处理一个html表单,它捕获了典型的名称和电子邮件,我已经在工作了。典型的表单提交到php页面 我现在要做的是根据选中的单选按钮(有10个)捕获单选按钮的值。当用户提交表单时,我希望根据选择的无线电值将用户重定向到十页中的一页 例如,如果选中了radio 1,则转到page1.html,如果选中了Page2,则转到Page2.html等 所以我想在我的php文件中需要一个IF语句,它可能会检查switch类的值,然后根据该值重定向到相关页面。我不太会使用php,所以我不能完全确定执行此

我正在尝试处理一个html表单,它捕获了典型的名称和电子邮件,我已经在工作了。典型的表单提交到php页面

我现在要做的是根据选中的单选按钮(有10个)捕获单选按钮的值。当用户提交表单时,我希望根据选择的无线电值将用户重定向到十页中的一页

例如,如果选中了radio 1,则转到page1.html,如果选中了Page2,则转到Page2.html等

所以我想在我的php文件中需要一个IF语句,它可能会检查switch类的值,然后根据该值重定向到相关页面。我不太会使用php,所以我不能完全确定执行此操作的正确过程

任何帮助都将不胜感激。向尼克问好

HTML


1.
2.
3.
4.
5.
6.
7.
8.
9
10
提交评级
PHP


问题似乎缺少某些细节,但你可以考虑以下几点。无论如何,这是一种方法

if( $_SERVER['REQUEST_METHOD']=='POST' && !empty( $_POST['switch'] ) ){


    function geturl( $i ){
        switch( $i ){
            case 1: return 'http://www.example.com';
            case 2: return 'http://www.foo.com';
            case 3: return 'http://bar.com';
            /* etc */
        }   
    }


    $redirect = geturl( intval( $_POST['switch'] ) );
    header("Location: {$redirect}");

}

您引用的重定向代码在哪里?网址是什么?它们与复选框有什么关系?或者-你的实际问题是什么?到目前为止,你只告诉我们你“想要”什么。请阅读。我已经更新了线程:)
<?php
// configure
$from = 'Landing Page Feedback Form <nick@test.co.uk>'; 
$sendTo = 'Nick <nick@test.co.uk>';
$subject = 'You Have Some New Feedback On Your Landing Page!';
$fields = array('name' => 'Name', 'email' => 'Email'); // array variable name => Text to appear in email
$okMessage = 'Thank, We will get back to you soon!';
$errorMessage = 'There was an error while submitting the form. Please try again';



// let's do the sending

try
{
    $emailText = "A new lead has been generated via the landing page, details captured follow. \n \n";

    foreach ($_POST as $key => $value) {

        if (isset($fields[$key])) {
            $emailText .= "$fields[$key]: $value\n";
        }
    }

    mail($sendTo, $subject, $emailText, "From: " . $from);

    $responseArray = array('type' => 'success', 'message' => $okMessage);
}
catch (\Exception $e)
{
    $responseArray = array('type' => 'danger', 'message' => $errorMessage);
}

if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
    $encoded = json_encode($responseArray);

    header('Content-Type: application/json');

    echo $encoded;
}
else {
    echo $responseArray['message'];
}
if( $_SERVER['REQUEST_METHOD']=='POST' && !empty( $_POST['switch'] ) ){


    function geturl( $i ){
        switch( $i ){
            case 1: return 'http://www.example.com';
            case 2: return 'http://www.foo.com';
            case 3: return 'http://bar.com';
            /* etc */
        }   
    }


    $redirect = geturl( intval( $_POST['switch'] ) );
    header("Location: {$redirect}");

}