我對我的html頁面有一些麻煩。我想在按下提交按鈕後重新加載。我試着用JavaScript重新加載它,但它不斷給我一個白頁(在我需要的文件保存後)。提交按鈕上的空白頁面
下面是HTML代碼:
<html>
<head>
<title>Sample Web Form</title>
</head>
<body>
<h1>Fill Out This Form</h1>
<form action="myprocessingscript.php" method="POST">
<p><i>Choose one or more of the available options that represent the current mental state of the System:</i></p>
<input type="checkbox" name="mentalState[]" value="Knows user culture"> Knows User Culture<br>
<input type="checkbox" name="mentalState[]" value="Knows concept "> Knows Concept<br>
<input type="checkbox" name="mentalState[]" value="Knows that user knows concept"> Knows that User Knows Concept<br>
<p><i>Choose the corresponding action:</i></p>
<input type="checkbox" name="action" value="cultureIdentif"> Culture Identification<br>
<input type="checkbox" name="action" value="conceptIdentif"> Concept Identification<br>
<p><i>Choose one or more of the available options that represent the current mental state of the System following the action:</i></p>
<input type="checkbox" name="mentalState2[]" value="Knows user culture"> Knows User Culture<br>
<input type="checkbox" name="mentalState2[]" value="Knows concept"> Knows Concept<br>
<input type="checkbox" name="mentalState2[]" value="Knows that user knows concept"> Knows that User Knows Concept<br>
</br>
<input type="submit" value="Save Data">
</form>
</body>
</html>
這裏是PHP代碼:
<?php
if(!empty($_POST['mentalState'])){
// Loop to store and display values of individual checked checkbox.
foreach($_POST['mentalState'] as $mentalState)
($mentalState1=$mentalState . ',' . $mentalState1);
}
if(!empty($_POST['mentalState2'])){
// Loop to store and display values of individual checked checkbox.
foreach($_POST['mentalState2'] as $mentalState)
($mentalState2=$mentalState . ',' . $mentalState2);
}
if(isset($mentalState1) && isset($_POST['action']) && isset($mentalState2)) {
$data = $mentalState1 . '-' . $_POST['action'] . '-' . $mentalState2 . "\n";
$ret = file_put_contents('matrix.txt', $data, FILE_APPEND | LOCK_EX);
if($ret === false) {
die('There was an error writing this file');
}
} else {
die('no post data to process');
}
感謝您的幫助!
地方'標題(「位置:$ _ SERVER [」 HTTP_REFERER']「);'在你最後的'IF'語句中,當它完成而沒有錯誤時,它會將你重定向回你提交的頁面。 – Blinkydamo
你能寫出這個文件嗎? –
一些明智的代碼縮進將是一個好主意。它可以幫助我們閱讀代碼,更重要的是,它可以幫助您**調試您的代碼** [快速瀏覽編碼標準](http://www.php-fig.org/psr/psr-2/ )爲了您自己的利益。 – RiggsFolly