duanjian5059 2013-10-09 15:27
浏览 31

PHP表单 - 如何根据单个下拉选项将用户定向到特定页面,AS WELL AS预先填充目标页面,其中包含一些给定的输入

Bit of a weird one (for me at least...)

I want to have the user complete a small form in order to proceed with an application for two different types of finance (name, email, contact etc). The user is also required to specify the type of finance they would like, and submitting the form takes the user to the full application for that finance type. I can already do this.

I also would like the input given in the initial form to be carried over to the full application. I can do this also.

My problem is, I can't get both of these features working together at the same time!

Initial Form:

<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.'' );
    }
?>

Target page:

<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>

This is my first time posting on here, please forgive me if I have left out anything obvious and I will answer any questions as best I can.

Cheers!

  • 写回答

1条回答 默认 最新

  • drwghu6386 2013-10-09 15:38
    关注

    You can try registering the ddAppType in session or in cookies.

    Sessions and cookies let you register some values in some stage of the session and you can also retrieve them when you want (depening on the expiry time that you set for those values).

    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题