由于下拉形式,无法修改标题信息?

时间:2015-12-11 06:49:18

标签: php html forms

我的代码有一个用户输入表单,他们输入地址,城市,州和邮政编码。

我的代码没有州的下拉表单。

我需要将用户引导到帐户创建过程的下一部分,因此我在header("location: nextpage.php")的IF语句中使用isset(($_POST['submitbutton'])。有没有其他方式指向此页面?我是否必须删除状态下拉框才能使用标题功能?

<!DOCTYPE html>
<html lang="en">

<?php
//Start the session
session_start();
?>


<head>
    <title>Placeholder</title>
    <meta charset="utf-8">

<!--*** External CSS Link ***-->
<link href="style.css" rel="stylesheet">    
</head>
<body>


<!--*** Header ***-->    
<header><?php include 'inc_header_aries0653.php';?></header>


<!--*** H tags ***-->        
<h1>New Account Creation</h1>    




<!--*** Form Start ***-->    
<form method="post" name="Lab5Form" id="Lab5Form" 
      action="#">
    <fieldset>
        <legend>Address</legend>



        <!-- Form Fields [All Required] -->

         <!-- Street Address -->
        <label for="address">Street Address: </label><br>
        <input type="text" name="address" id="address" size="30" 
                             maxlength="30" placeholder= "51 Groom Lake" 
                             required="required"><br><br>

         <!-- City -->
        <label for="city">City: </label><br> 
        <input type="text" name="city" id="city" 
                             size="30" 
                             maxlength="20" placeholder= "Roswell" 
                             required="required"><br><br>  


         <!-- State -->  
        <label for="state">State: </label><br>
        <select name="state" id="state">
            <option value="AL">Alabama</option>
            <option value="AK">Alaska</option>
            <option value="AZ">Arizona</option>
            <option value="AR">Arkansas</option>
            <option value="CA">California</option>
            <option value="CO">Colorado</option>
            <option value="CT">Connecticut</option>
            <option value="DE">Delaware</option>
            <option value="DC">District of Columbia</option>
            <option value="FL">Florida</option>
            <option value="GA">Georgia</option>
            <option value="HI">Hawaii</option>
            <option value="ID">Idaho</option>
            <option value="IL">Illinois</option>
            <option value="IN">Indiana</option>
            <option value="IA">Iowa</option>
            <option value="KS">Kansas</option>
            <option value="KY">Kentucky</option>
            <option value="LA">Louisiana</option>
            <option value="ME">Maine</option>
            <option value="MD">Maryland</option>
            <option value="MA">Massachusetts</option>
            <option value="MI">Michigan</option>
            <option value="MN">Minnesota</option>
            <option value="MS">Mississippi</option>
            <option value="MO">Missouri</option>
            <option value="MT">Montana</option>
            <option value="NE">Nebraska</option>
            <option value="NV">Nevada</option>
            <option value="NH">New Hampshire</option>
            <option value="NJ">New Jersey</option>
            <option value="NM" selected>New Mexico</option>
            <option value="NY">New York</option>
            <option value="NC">North Carolina</option>
            <option value="ND">North Dakota</option>
            <option value="OH">Ohio</option>
            <option value="OK">Oklahoma</option>
            <option value="OR">Oregon</option>
            <option value="PA">Pennsylvania</option>
            <option value="RI">Rhode Island</option>
            <option value="SC">South Carolina</option>
            <option value="SD">South Dakota</option>
            <option value="TN">Tennessee</option>
            <option value="TX">Texas</option>
            <option value="UT">Utah</option>
            <option value="VT">Vermont</option>
            <option value="VA">Virginia</option>
            <option value="WA">Washington</option>
            <option value="WV">West Virginia</option>
            <option value="WI">Wisconsin</option>
            <option value="WY">Wyoming</option>
        </select><br><br>



        <!-- Zip Code [Size=10] -->
        <label for="zip">Zip Code: </label><br> 
        <input type="text" name="zip" id="zip" size="10" 
                             maxlength="10" placeholder= "30077-XXXX" 
                             required="required"><br><br>   


        <!--Submit/Reset Buttons -->    
        <input type="submit" value="Submit" name="submitbtn id="submit"> 
        <input type="reset">
    </fieldset>
    </form>

<!-- PHP -->  
<?php
//require_once functions
require_once ("inc_functions.php");


//filter_input from POST form
 $add = (filter_input(INPUT_POST, 'address'));
 $ct = (filter_input(INPUT_POST, 'city'));
 $st = (filter_input(INPUT_POST, 'state'));
 $zp = (filter_input(INPUT_POST, 'zip'));


 //manipulating user form input for less errors/security
 $address = (ucwords(strtolower(trim($add)))); 
 $city    = (ucwords(strtolower(trim($ct))));
 $state   = ($st);
 $zip     = (trim($zp));



  //if submitbutton is not clicked, die
  if (isset($_POST['submitbtn'])){

//RegEx Functions Run on each input field, see [inc_functions_aries0653]
// Grouped by function, not order
AddCheck ($address);
NameCheck ($city);
ZipCheck ($zip);


// Set session variables
$_SESSION["address"] = $address;
$_SESSION["city"]    = $city;
$_SESSION["state"]   = $state;
$_SESSION["zip"]     = $zip;


header("location: AccessInfo.php");        
}


?>

1 个答案:

答案 0 :(得分:0)

确定。第一个解决方案是错误的。

在会话开始之前你应该没有输出,你应该缓冲你的输出。

<?php
//Start the session
session_start();
ob_start();
?>

<!DOCTYPE html>
<html lang="en">
...

然后你应该更正你的表单提交ID:

<!--Submit/Reset Buttons -->    
<input type="submit" value="Submit" name="submitbtn" id="submit">

在代码的最后:

//if submitbutton is not clicked, die
if (isset($_POST['submitbtn'])){

    //...

    header("Location: AccessInfo.php");        
}
ob_end_flush();
?>