0
我有一個頁面,需要在客戶的詳細信息,並按下提交後,數據被髮送到一個單獨的文件中的PHP函數進行驗證。如果輸入的數據不正確,會彈出一個框,提供有關錯誤的詳細信息。該函數應該返回一個href,以便放入一個<a>
標籤,以便客戶可以再試一次。這個href包含他們作爲一個數組輸入的細節。我已經在各個階段迴應了這個href,它工作正常。但是,當點擊鏈接時,它不會在URL中插入整個數組。從PHP傳遞數組到頭部,href不是全長
的轉換由json_encode完成和解碼
IF語句,其中該陣列被轉換爲字符串:
if($check == 'false' and $checkNO == 1){
//if there are empty fields
echo "<div class='head'>Failed to place order <br><br></div>";
echo $error['empty'];
$pass_details = json_encode($details);
return "order_form.php?main_pkey=$stockID&details=$pass_details";
}elseif($check == 'false' and $checkNO == 2){
//if the fieled are filled in incorrectly
echo "<div class='head'>Failed to place order <br><br></div>";
foreach($error as $value){
echo $value;
}
$pass_details = json_encode($details);
return "order_form.php?main_pkey=$stockID&details=$pass_details";
}elseif($check == 'true'){
//convert array to string so that it can be passed to the confirm page in the headder
$pass_details = json_encode($details);
//direct to confirm
header("Location: confirm.php?main_pkey=$stockID&details=$pass_details");
}
郵購表格的頁面,該字符串被轉換回的陣列:
if(isset($_GET['details'])){
$details = json_decode($_GET['details'], true);
}else{
$details = array("title" => "", "fname" => "", "sname" => "", "address1" => "", "address2" => "", "post" => "", "email" => "", "quantity" => "", "comment" => "");
}
if (isset($_POST["order_form"])){
echo '<div id="openModal" class="modalbg">
<div class="dialog">';
$href = validateorderform($stockID);
echo '<a href=' . $href . ' title="Close" class="close"><x>X</x></a>
</div>
</div>';
}
這就是出現在地址欄曾經的「x」按:
order_form.php?main_pkey=1&details={"title":"Mr","fname":"data
http://php.net/manual/en/function.urlencode.php – AbraCadaver