PHP表单 - 如何根据单个下拉选项将用户定向到特定页面,以及使用一些给定的输入预填充目标页面


PHP form - how to direct user to specific page based on single drop down choice, AS WELL AS pre-populate target page withsome given inputs

有点

奇怪(至少对我来说...

我想让用户填写一个小表格,以便继续申请两种不同类型的财务(姓名、电子邮件、联系人等(。用户还需要指定他们想要的财务类型,提交表格会将用户带到该财务类型的完整申请。我已经可以做到了。

我还希望将初始表格中给出的意见转入整个申请。我也可以这样做。

我的问题是,我无法同时让这两个功能协同工作!

初始形式:

<form method="post" action="form.starterApp.php" name="applyStart" id="applyStart">
    <table class="applyStart formTable" style="margin-right:20px;">
        <tr>
            <td colspan="2">
                <label for="ddAppType">Would you like to apply for Car Finance or a Logbook Loan?</label><br />
                <select name="ddAppType" id="ddAppType">
                    <option value="Car Finance">Car Finance</option>
                    <option value="Logbook Loan">Logbook Loan</option>
                </select>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <label for="txtName">Your Name</label><br />
                <input name="txtName" type="text" id="txtName" value="" />
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <label for="txtEmail">Your Email</label><br />
                <input name="txtEmail" type="text" id="txtEmail" value="" />
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <label for="txtNumber">Your Contact Number</label><br />
                <input name="txtNumber" type="text" id="txtNumber" value="" />
            </td>
        </tr>
        <tr>
            <td>
                <label for="chkAge" class="chkAge">Are you over 18 years of age?</label>
            </td>
            <td>
                <input type="checkbox" name="chkAge" id="chkAge" />
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="submit" class="submit" id="submit" value="Submit" />
            </td>
        </tr>
    </table>
</form>

Action Script (form.starterApp.php(:

<?php
    if(!$_POST) exit;
    // Only edit below this line if either instructed to do so by the author or have extensive PHP knowledge.
    // Please Note, we cannot support this file package if modifications have been made below this line.
    $ddAppType      = $_POST['ddAppType'];
    $txtName        = $_POST['txtName'];
    $chkAge         = $_POST['chkAge'];
    $txtEmail       = $_POST['txtEmail'];
    $txtNumber      = $_POST['txtNumber'];
    $ifFinance  = 'apply-for-finance';
    $ifLogbook  = 'apply-for-logbook';

    //Setting the Application Type
    if ($ddAppType == 'Car Finance') {
        $appType = $ifFinance;
    }
    else if ($ddAppType == 'Logbook Loan') {
        $appType = $ifLogbook;
    }
    {
        header( 'Location: '.$appType.'' );
    }
?>

目标页面:

<form method="post" action="form.fullApplication.php" name="applyFinance" id="applyFinance">
<table class="applyFinance formTable" style="margin-right:20px;">
    <tr>
        <td colspan="2">
            <label for="txtName">Your Name</label><br />
            <input name="txtName" type="text" id="txtName" value="<?php echo $_POST["txtName"]; ?>" />
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <label for="txtEmail">Your Email</label><br />
            <input name="txtEmail" type="text" id="txtEmail" value="" />
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <label for="txtNumber">Your Contact Number</label><br />
            <input name="txtNumber" type="text" id="txtNumber" value="" />
        </td>
    </tr>
    <tr>
        <td>
            <label for="chkAge" class="chkAge">Are you over 18 years of age?</label>
        </td>
        <td>
            <input type="checkbox" name="chkAge" id="chkAge" />
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <input type="submit" class="submit" id="submit" value="Submit" />
        </td>
    </tr>
</table>

这是我第一次在这里发帖,如果我遗漏了任何明显的东西,请原谅我,我会尽我所能回答任何问题。

干杯!

您可以尝试在会话或 cookie 中注册 ddAppType。

会话和 Cookie 允许您在会话的某个阶段注册一些值,您也可以在需要时检索它们(根据您为这些值设置的到期时间而定(。