2012-01-30 48 views
0

由于某种原因,如果在我的表单上犯了一个错误,那么url变量会消失,并且必须有一种方法来保留它们。我是PHP新手,PHP Form Builder Class很新,所以我无法弄清楚。我的表单页面看起来像:如何在使用PHP Form Builder Class提交表单提交后保留url变量

<?php 
require_once '../site_globals/FirePHP.class.php'; 
ob_start(); 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<title>Step Two: Physician Supervisor Feedback</title> 
<link rel="stylesheet" type="text/css" href="../css/view.css" media="all" /> 
</head> 
<body id="main_body" > 
<img id="top" src="../images/top.png" alt="" /> 
<div id="form_container"> 
    <div id="form_container" style="background-color: #004F79; height:45px;"></div> 
    <div style="padding:30px;"> 
    <div class="form_description"> 
     <h2>Step Two: Physician Supervisor Feedback</h2> 
     <p></p> 
    </div> 
    <?php 
session_start(); 
$hide = $_GET['id']; 
$hide1 = $_GET['hash']; 
include '../site_globals/dbc.php'; 
error_reporting(0); 
include("../PFBC/Form.php"); 
if (isset($_POST["form"])) { 
    if (Form::isValid($_POST["form"])) { 
     /*The form's submitted data has been validated. Your script can now proceed with any 
     further processing required.*/ 
     $name  = filter($_POST['name']); 
     $title  = filter($_POST['title']); 
     $email  = filter($_POST['email']); 
     $fina  = filter($_POST['fina']); 
     $status  = filter($_POST['status']); 
     $comments = filter($_POST['comments']); 
     $date  = filter($_POST['date+']); 
     $hidden  = filter($_POST['hidden']); 
     $hiddenhash = filter($_POST['hiddenhash']); 
     //Run first query to input POSTS into table 
     $query_1 = "UPDATE usc_table SET name_2='$name', title_2='$title', email='$email', financial='$fina', status_2='$status', comments='$comments', date_2='$date' WHERE submission_id='$hidden'"; 
     $things = mysql_query($query_1) or die(mysql_error()); 
     //Run second query to update feedback column in submissions 
     $query_2 = "UPDATE submissions SET feedback=3 WHERE submission_id=$hidden"; 
     mysql_query($query_2) or die(mysql_error()); 
     INCLUDE '../site_hospital01/pdfmaker_2.php'; 
     echo "Thank You, Your Feedback Has Been Submitted."; 
    } else { 
     /*Validation errors have been found. We now need to redirect back to the 
     script where your form exists so the errors can be corrected and the form 
     re-submitted.*/ 
     $hide = $_GET['id']; 
     $hide1 = $_GET['hash']; 
     $firephp = FirePHP::getInstance(true); 
     $firephp->log("$hide", 'Iterators'); 
     $pageURL = $_SERVER['REQUEST_URI'] . "?id=" . $hide . "&&hash=" . $hide1; 
     header("Location: " . $pageURL); 
    } 
    exit(); 
} 
?> 
<?php 
$hide  = $_GET['id']; 
$hide1 = $_GET['hash']; 
$options = array(
    "Order as needed", 
    "Shelf Stock", 
    "Consignment" 
); 
$options1 = array(
    "Approved", 
    "Denied" 
); 
$form  = new Form("anything", 700); 
$form->addElement(new Element_Hidden("form", "anything")); 
$form->addElement(new Element_Textbox("Name:", "name", array(
    "required" => 1 
))); 
$form->addElement(new Element_Textbox("Title:", "title", array(
    "required" => 1 
))); 
$form->addElement(new Element_Textbox("Email:", "email", array(
    "required" => 1 
))); 
$form->addElement(new Element_YesNo("Do you have a financial interest in the manufacturer of this product:", "fina", array(
    "required" => 1 
))); 
$form->addElement(new Element_Radio("Status of this request:", "status", $options1, array(
    "inline" => 1, 
    "required" => 1 
))); 
$form->addElement(new Element_Textarea("Comments:", "comments", array(
    "required" => 0 
))); 
$form->addElement(new Element_Date("Date:", "date+")); 
$form->addElement(new Element_Hidden("hidden", "$hide")); 
$form->addElement(new Element_Hidden("hiddenhash", "$hide1")); 
$form->addElement(new Element_Button); 
$form->render(); 
//var_dump(get_defined_vars()); 
?> 
</div> 
</div> 
<img id="bottom" src="../images/bottom.png" alt="" /> 
</body> 

</html> 
<?php 
ob_end_flush(); 
?> 

它是活在http://supplychex.com/site_hospital01/feedback_2.php?id=&&hash=

如何保持现有的URL变量的形式提交后,如果有错误,任何想法?我尝试了几件事,每次都消失。我希望比我聪明的人能告诉我他们将如何处理这件事。我曾尝试将网页重定向到本网站上的每个建议网址,这意味着将url变量保留在原位并令人沮丧地仍然消失。我已经考虑过隐藏的字段,但是由于出现错误,表单没有发布。帮助....

回答

3

我认为Form Builder类的用法是不必要的,修改从else { /*Validation errors have been found. We now need to redirect back to the script where your form exists so the errors can be corrected and the form re-submitted.*/开始的代码并手动编写表单。然后为您希望保留的每个元素添加value="<?php echo $_POST['whatever']; ?>

+0

我有更大的使用PFBC的商业理由。我将来需要创建许多这样的表单,并且从设计的角度来看,这个类可以非常简单地快速构建表单。因为这个问题,我希望我不必重做所有的表格。如果我要使用PFBC如何将GET变量拉入else语句,你会有什么想法吗?谢谢。 – 2012-01-30 19:56:51

+0

想通了。只需在if(isset($ _ POST [“form”]))之后立即捕获隐藏的字段,那么它们在else语句中可用于添加到url中,并且在表单中存在错误时可用。 – 2012-01-30 21:53:38