本文介绍了提交按钮上的空白页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的html页面有些麻烦。我想在按下提交按钮后重新加载。我试着用javascript重新加载它,但它一直给我一个白页(在将需要的数据保存到文件中后)。
以下是html代码:
< html>
< head>
< title>示例Web表单< / title>
< / head>
< body>
< h1>填写此表单< / h1>
< form action =myprocessingscript.phpmethod =POST>
< p>< i>选择一个或多个表示系统当前心理状态的可用选项:< / i>< / p>
< input type =checkboxname =mentalState []value =了解用户文化>了解用户文化< br>
< input type =checkboxname =mentalState []value =知道概念>了解概念< br>
< input type =checkboxname =mentalState []value =知道用户知道概念>知道用户知道概念< br>
< p>< i>选择相应的操作:< / i>< / p>
< input type =checkboxname =actionvalue =cultureIdentif>文化认同< br>
< input type =checkboxname =actionvalue =conceptIdentif>概念识别< br>
< p>< i>选择一个或多个可用选项,以表示动作后系统的当前心理状态:< / i>< / p> ;
< input type =checkboxname =mentalState2 []value =了解用户文化>了解用户文化< br>
< input type =checkboxname =mentalState2 []value =知道概念>了解概念< br>
< input type =checkboxname =mentalState2 []value =知道用户知道概念>知道用户知道概念< br>
< / br>
< input type =submitvalue =保存数据>
< / form>
< / body>
< / html>
这里是php代码:
<$ p $($ _ POST ['mentalState'])){
//循环存储和显示个别选中的复选框的值。
foreach($ _ POST ['mentalState'] as $ mentalState)
($ mentalState1 = $ mentalState。','。$ mentalState1);
}
if(!empty($ _ POST ['mentalState2'])){
//循环存储并显示单个复选框的值。
foreach($ _ POST ['mentalState2']为$ mentalState)
($ mentalState2 = $ mentalState。','。$ mentalState2); ($心理状态1)&&& isset($ _ POST ['动作'])&& isset($ mentalState2)){
}
b $ b $ data = $ mentalState1。 ' - '。 $ _POST ['action']。 ' - '。 $ mentalState2。 \\\
;
$ ret = file_put_contents('matrix.txt',$ data,FILE_APPEND | LOCK_EX);
if($ ret === false){
die('写这个文件时出错');
}
} else {
die('没有发布数据到流程');
}
感谢您的帮助!
解决方案
我认为您在这里缺少一个条件
您只有
if($ ret === false){
die('写这个文件时出错');
}
尝试添加else并参阅
if($ ret === false){
die('写这个文件时出错');
} else {
header('Location:'。$ _SERVER ['HTTP_REFERER']);
}
I have some troubles with my html page. I want it to reload after pressing the submit button. I tried reloading it with javascript but it keeps on giving me a white page (after saving the data I need in a file).
Here is the html code:
<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>
here is the php code:
<?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');
}
Thanks for your help!
解决方案
I think you are missing one condition here
you have only
if($ret === false) {
die('There was an error writing this file');
}
try to add the else and see
if($ret === false) {
die('There was an error writing this file');
} else {
header('Location: ' . $_SERVER['HTTP_REFERER']);
}
这篇关于提交按钮上的空白页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!