PHP表单处理来自查询字符串的预填表单

时间:2013-10-21 15:10:32

标签: php forms query-string

我正在尝试使用查询字符串预先填写表单并让用户进行任何必要的更改然后按提交并进行表单处理并向管理员发送电子邮件以执行他们需要执行的任何操作随着信息。

我正在使用PHP填充表单,我开始使用a tutorial from NetTuts进行电子邮件表单处理,因为它进行了内联验证。希望验证不是必需的,因为所有字段都已预先填写但我想要进行表单检查以确保用户在提交表单之前不清除字段。我不知道为什么表格不能正确处理。

我的表单与教程之间的唯一变化是变量名,包含和一些$_GET超全局用于从查询字符串中获取表单数据,以及使用echo从{填写表单{1}}超级全局代替会话数据,如果用户提交表单而不填写所有内容。其他所有内容都已从教程中逐字复制。

任何有助于解决这个问题的帮助,即使它正在重新思考如何做到这一点,也会非常感激。

以下是表单页面和处理页面的代码。

表单页面

$_GET

处理页面

<?php
session_start();

// site root folder
$root_folder = "/meetingplannersignup";

//get values of displayed form fields from URL
$FirstName= $_GET['FirstName'];
$LastName = $_GET['LastName'];
$Organization = $_GET['Organization'];
$EmailAddress = $_GET['EmailAddress'];
$Phone = $_GET['Phone'];
$EventType = $_GET['EventType'];
$EventName = $_GET['EventName'];
$EventLocation = $_GET['EventLocation'];
$HotelName = $_GET['HotelName'];
$EventStart = $_GET['EventStart'];
$EventEnd = $_GET['EventEnd'];

// get values of hidden form fields from URL
$ExtReferenceID = $_GET['ExtReferenceID'];
$City = $_GET['City'];
$State = $_GET['State'];
$ZipCode = $_GET['ZipCode'];
$CountryCode = $_GET['CountryCode'];
?>
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--><html class="no-js" lang="en" > <!--<![endif]-->

    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width">
        <title>Simplify Event Management with GroupMAX</title>

        <link rel="stylesheet" href="<?php echo $root_url ?>/assets/css/bootstrap.css">

    </head>
    <body>
        <div class="container">

<!-- begin main nav -->
            <nav class="navbar navbar-static-top navbar-inverse" role="navigation">
                <!-- Brand and toggle get grouped for better mobile display -->
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-main-collapse">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                </div>

                <!-- Collect the nav links, forms, and other content for toggling -->
                <div class="collapse navbar-collapse navbar-main-collapse">
                    <ul class="nav navbar-nav">
                        <li class="active"><a href="<?php echo $root_url ?>">home</a></li>
                        <li><a href="<?php echo $root_url ?>/index.php?FirstName=Todd&LastName=Bailey&Organization=Passkey%20International,%20Inc.&EmailAddress=tbailey@passkey.com&Phone=781-373-4100&EventType=event type&EventName=event%20name&EventLocation=Honolulu,%20Hawaii&HotelName=Marriott%20Resorts&&EventStart=11/20/2013&EventEnd=11/24/2013&ExtReferenceID&City=Waltham&State=MA&ZipCode=02453&CountryCode=US">fill out form</a></li>
                    </ul>
                </div><!-- /.navbar-collapse -->
            </nav>
<!-- end main nav -->

            <div class="row">
                <div class="col-lg-12">
                    <h1>Simplify Event Management with GroupMAX</h1>
                    <h3>Impress Your Attendees. Optimize Your Event.</h3>
                    <hr />
                </div>
            </div>

            <div class="row">
                <div class="col-lg-6">
                    <h4>Included Features are:</h4>
                    <ul>
                        <li><strong>Event Booking Websites – </strong>Passkey’s award winning booking website allows for personalized hotel reservation website where attendees can make, modify or cancel their hotel bookings directly into that group's contracted block.</li>
                        <li><strong>Integrated with Event Registration - </strong>RegLink&trade; is an integration technology that can link any online planner registration solution to Passkey's best-in-class hotel reservation system, allowing meeting planners to integrate hotel reservations directly into their event registration process.</li>
                        <li><strong>Event Dashboard – </strong>With Event Dashboard Planners can track their events, manage their lists and monitor reservations anytime online. With Passkey’s LiveView Dashboards, meeting planners can get an instant snapshot of their event in a fun, interactive environment. </li>
                        <li><strong>SmartAlerts&trade; - </strong>Automatic e-mails containing vital event information that are automatically sent out to a list of recipients at specific intervals or critical event milestones.</li>
                    </ul>
                </div>

                <div class="col-lg-6">
                    <div class="row">
                        <div class="col-lg-12">

<!-- begin error processing -->
                            <div class="well">
                                <?php
                                    //init variables
                                    $cf = array();
                                    $sr = false;

                                    if(isset($_SESSION['cf_returndata'])){
                                        $cf = $_SESSION['cf_returndata'];
                                        $sr = true;
                                    }
                                ?>
                                <div id="errors" class="alert alert-danger<?php echo ($sr && !$cf['form_ok']) ? ' show_alert' : ''; ?>">
                                    <p>There were some problems with your form submission:</p>
                                    <ul>
                                    <?php 
                                        if(isset($cf['errors']) && count($cf['errors']) > 0) :
                                            foreach($cf['errors'] as $error) :
                                    ?>
                                    <li><?php echo $error ?></li>
                                    <?php
                                            endforeach;
                                        endif;
                                    ?>
                                    <?php
                                        //init variables
                                        $cf = array();
                                        $sr = false;

                                        if(isset($_SESSION['cf_returndata'])){
                                            $cf = $_SESSION['cf_returndata'];
                                            $sr = true;
                                        }
                                    ?>
                                    </ul>
                                </div>
                                <p id="success" class="alert alert-success<?php echo ($sr && $cf['form_ok']) ? ' show_alert' : ''; ?>">Thanks for your message! We will get back to you ASAP!</p>
<!-- end error processing -->
<!-- begin form -->
                                <fieldset>
                                    <legend>Your Information</legend>
                                    <p>Please review the pre-filled information and correct any inaccurate information prior to submitting the form.</p>
                                    <form method="post" action="process.php">
                                        <div class="form-group">
                                            <label>First Name</label>
                                            <input type="text" class="form-control" id="FirstName" value="<?php echo ($sr && !$cf['form_ok']) ? $cf['posted_form_data']['FirstName'] : '' ?><?php echo $FirstName; ?>">
                                        </div>
                                        <div class="form-group">
                                            <label>Last Name</label>
                                            <input type="text" class="form-control" id="LastName" value="<?php echo $LastName; ?>">
                                        </div>
                                        <div class="form-group">
                                            <label>Company/Organization</label>
                                            <input type="text" class="form-control" id="Organization" value="<?php echo $Organization; ?>">
                                        </div>
                                        <div class="form-group">
                                            <label>Email Address</label>
                                            <input type="text" class="form-control" id="EmailAddress" value="<?php echo $EmailAddress; ?>">
                                        </div>
                                        <div class="form-group">
                                            <label>Phone Number</label>
                                            <input type="text" class="form-control" id="Phone" value="<?php echo $Phone; ?>">
                                        </div>
                                        <div class="form-group">
                                            <label>Event Type</label>
                                            <input type="text" class="form-control" id="EventType" value="<?php echo $EventType; ?>">
                                        </div>
                                        <div class="form-group">
                                            <label>Event Name</label>
                                            <input type="text" class="form-control" id="EventName" value="<?php echo $EventName; ?>">
                                        </div>
                                        <div class="form-group">
                                            <label>Event Location</label>
                                            <input type="text" class="form-control" id="EventLocation" value="<?php echo $EventLocation; ?>">
                                        </div>
                                        <div class="form-group">
                                            <label>Hotel Name</label>
                                            <input type="text" class="form-control" id="HotelName" value="<?php echo $HotelName; ?>">
                                        </div>
                                        <div class="form-group">
                                            <label>Start/Arrival Date</label>
                                            <input type="text" class="form-control" id="EventStart" value="<?php echo $EventStart; ?>">
                                        </div>
                                        <div class="form-group">
                                            <label>End Date</label>
                                            <input type="text" class="form-control" id="EventEnd" value="<?php echo $EventEnd; ?>">
                                        </div>
                                        <hr />
                                        <input type="submit" value="Submit" class="btn btn-primary" />

                                        <!--hidden fields-->
                                        <input type="hidden" id="ExtReferenceID" value="<?php echo $ExtReferenceID; ?>">
                                        <input type="hidden" id="City" value="<?php echo $City; ?>">
                                        <input type="hidden" id="State" value="<?php echo $State; ?>">
                                        <input type="hidden" id="ZipCode" value="<?php echo $ZipCode; ?>">
                                        <input type="hidden" id="CountryCode" value="<?php echo $CountryCode; ?>">

                                    </form>
                                    <?php unset($_SESSION['cf_returndata']); ?>
                                </fieldset>
                            </div>
<!-- end form -->

                        </div>
                    </div>
                </div>
            </div>
        </div>

    </body>
</html>

1 个答案:

答案 0 :(得分:1)

几个问题:

<强> 1。 isset($_POST)永远是真的

在您的处理页面中,您需要检查:

if( isset($_POST) )

即使true为空,也始终评估为$_POST。您应该检查特定字段以尝试并猜测表单已提交

<强> 2。您使用id代替name

通过POST发送的表单值通过name标识,而不是通过id标识。在HTML中,您可以保留id属性,但对于要发布的每个字段,您必须添加name属性:

<input type="text" class="form-control" name="LastName" id="LastName" value="<?php echo $LastName; ?>">
如果您只使用$_POST['LastName']标识表单控件,则

id为空。

我没有检查其余的,但你应该先尝试修复这些点。