我有點迷路,我試圖放置一個鏈接返回到「窗體」頁面或「主頁」頁面爲每個錯誤消息,當用戶提交表單。當用戶成功提交表單時,它會將鏈接返回到表單頁面或主頁。基本上我想修復鏈接返回到表單或主頁。謝謝你們,請讓我知道我能做什麼或指導我。修復鏈接返回到表單或主頁
這也是迄今爲止該進程的一部分我的代碼:
<?php
//
//umask(0007)
//mkdir($newdir, 02770);
//$filename = "../../data/status.txt";
$errors = array();
$permissionsArray = (isset($_POST['permission']) ? $_POST['permission'] : null);
if (isset($_POST["statuscode"]))
{
$statusCode = $_POST["statuscode"];
$patternCode = "/^S[0-9]{4}$/";
if (preg_match($patternCode, $statusCode))
{
$ans = "";
$length = strlen($statusCode);
echo $statusCode . "<br />";
}
}
else
{
array_push($errors, "Please fill in Status Code as they are mandatory field");
}
if (isset ($_POST["status"]))
{
$status = $_POST["status"];
$pattern = "/^[a-zA-Z0-9\s\.,!?]*$/";
if (preg_match($pattern, $status))
{
echo $status . "<br />";
}
}
else
{
array_push($errors, "<b>Error:</b> Please fill in Status as they are mandatory field!");
}
if (isset ($_POST["share"]))
{
$shareButton = $_POST["share"];
echo $shareButton . "<br />";
}
else
{
//Not possible unless in exceptional circumstances
array_push($errors, "Please choose a share");
}
if (!isset($_POST["date"]))
{
$date = date("d/m/y");
echo $date . "<br />";
} else {
$date = $_POST["date"];
}
if (isset($permissionsArray))
{
foreach($permissionsArray as $permission){
echo $permission . "<br />";
}
}
if(isset($statusCode, $status))
{
if(empty($statusCode) || empty($status))
{
array_push($errors, "Please fill in the required part!");
}
if (0 === strlen($statusCode > 5 || $statusCode < 5))
{
array_push($errors, "<b>Error:</b> You characters length is either less or more than 5 characters<br/>");
}
if (0 === preg_match("/\S+/", $statusCode))
{
array_push($errors, "<b>Error:</b> You forgot to fill in Status Code!<br/>");
}
if (0 === preg_match("/\S+/", $status))
{
array_push($errors, "<b>Error:</b> You forgot to fill in the Status! <br/>");
}
if (0 === preg_match($patternCode, $statusCode))
{
array_push($errors, "<b>Error:</b> please make sure that the first letter in Status Code is uppercase 'S' following by 4 numbers. <br/>");
}
if (0 === preg_match($pattern, $status))
{
array_push($errors, "<b>Error:</b> Please make sure to avoid symbols other than \",.?!\" <br/>");
}
}
if (isset($errors))
{
foreach ($errors as $error)
{
echo '<strong>', $error, '</strong>';
}
}
?>
在表單打印代碼之前添加此錯誤消息代碼。 –
當出現錯誤時,不要讓它們返回。將表單提交給自己,在發佈數據時對其進行驗證,然後在表單上方顯示錯誤,將$ _POST中的所有值放在其各自的表單字段中。當表格按照你描述你的方式工作時,我會受到皇室的憤怒。我失去了我輸入的數據(主要問題),並且表單中還有一個額外的步驟,用戶通常不喜歡。只需內聯。在表單上方有一個'if(!empty($ _ POST ['some_field'])){//驗證碼}'。 – FluffyJack