2014-11-21 48 views
0

我有一种形式,POST数据,然后我需要收集这些数据,我知道该怎么使用做如何发布表单数据,收集数据然后重定向到页面?

$billingaddress = $post['firstname'] 

然后收集发布数据后,我需要重定向到一组URL

header(Location: www.google.com); 

我只是不确定在哪些文件需要包含哪些代码需要我需要收集数据和模拟重定向(它将去sagepay)的设置

回答

0

这就是你需要使用它的方式。

//Posted data stored in $_POST global array 
$billingaddress = $_POST['firstname']; 
//Do what you want. 
//Need to add quotes around the parameter 
//Need to use full URL started with the schema (http|https). 
header("Location: http://www.google.com"); 
//Terminate the script after redirect. 
exit; 

注意:你确定你要收集的名字到一个名为billingaddress变量?这是一个不好的做法。打电话给你的变量,它包括,例如:$firstName

+0

嘿,谢谢你的回答,生病之前给它。是的,这只是一个例子,我会修改这个问题。 – con322 2014-11-21 14:20:14

0

我不知道这是你问的问题,但从另一个问题在互联网的空虚某处,我设法找到一个好的表单设置。你需要3个文件:nameofform.phpnameofredirectpage.html,和一个地方来存储数据。以下是我的其中一个网站的示例。

表单页面

<?php 
if($_POST['formSubmit'] == "Submit") 
{ 
    $errorMessage = ""; 
    /* This section determines the error messages if there is a blank field. */ 
    if(empty($_POST['formSteam'])) 
    { 
     $errorMessage .= "<li>You need to put your Steam ID!</li>"; 
    } 
    if(empty($_POST['formName'])) 
    { 
     $errorMessage .= "<li>Please put your first and/or lastname!</li>"; 
    } 
    if(empty($_POST['formAge'])) 
    { 
     $errorMessage .= "<li>Please tell us your age! This is just for reference.</li>"; 
    } 
    if(empty($_POST['formPos'])) 
    { 
     $errorMessage .= "<li>You need to give us what position you want!</li>"; 
    } 
    if(empty($_POST['formApplication'])) 
    { 
     $errorMessage .= "<li>Do I have to explain this? Please explain why you want to be apart of our staff!</li>"; 
    } 
    /* This section just labels the variables. */ 
    $varSteam = $_POST['formSteam']; 
    $varName = $_POST['formName']; 
    $varAge = $_POST['formAge']; 
    $varApplication = $_POST['formApplication']; 
     $varPos = $_POST['formPos']; 
    /* This is where the magic happens. It's saying that if there is no errors and all the fields are filled in, it will open [or create] the file mydata.csv, which then writes each variable; `$varSteam`, `$varName`, `$varAge`, and so on. Grabbing what the fields content were, it will post the data in the specified order on the [newly created] file, then close the document. Finally, it redirects the user to the selected page, in this case "success.html". */ 
    if(empty($errorMessage)) 
    { 
     $fs = fopen("mydata.csv","a"); 
     fwrite($fs,$varSteam . ", " . $varName . ", " . $varAge . ", " . $varPos . ", " . $varApplication . "\n"); 
     fclose($fs); 

     header("Location: success.html"); 
     exit; 
    } 
} 
?> 
<html> 
<body> 

    <?php 
     if(!empty($errorMessage)) 
     { 
      echo("<p>There was an error with your form:</p>\n"); 
      echo("<ul>" . $errorMessage . "</ul>\n"); 
     } 
    ?> 
    /* This is the field ; change accordingly! */ 
    <form action="application.php" method="post"> 
     <p> 
      Whats your Steam ID? Find out <a href="http://www.steamidfinder.com">here!</a><br> 
      <input type="text" name="formSteam" maxlength="50" value="<?=$varSteam;?>"> 
     </p> 
     <p> 
      What is your name?<br> 
      <input type="text" name="formName" maxlength="50" value="<?=$varName;?>"> 
     </p>     
     <p> 
       How old are you?<br> 
       <input type="text" name="formAge" maxlength="2" value="<?=$varAge;?>"> 
     </p> 
     <p> 
       What position are you applying for?<br> 
       <select name="formPos" value="<?=$varPos;?>"> 
          <option value="">Pick an Option</option> 
          <option value="moderator">Moderator</option> 
          <option value="coder">Coder</option> 
          <option value="admin">Administrator</option> 
          <option value="other">Other</option> 
         </select> 
     </p> 
     <p> 
      Why do you want to apply for PossessedGaming Staff? *NOTE: If the above option was "OTHER", please include that "OTHER" position.<br> 
      <textarea name="formApplication" maxlength="3000" style="width:325px;height:150px;" value="<?=$varApplication;?>"></textarea> 
     </p> 
     <input type="submit" name="formSubmit" value="Submit"> 
    </form> 
</body> 
</html> 

重定向页面

<html> 


    <body> 
     <center> 
      <h1>Success!</h1> 
      <p>Your application will be reviewed by the staff ASAP. Thanks for applying!</p> 
     </body> 

    </html> 

我用的是我的网站工作人员申请表的例子;你可以相应地修改它。再次,不知道这是你想要的,但是...是的。

相关问题