我的逻辑是尝试验证两个文本字段(具体来说,如何检查错误字符串),并使用一个标志,如果关闭,用户将恢复到原始表单,而他的最新数据仍写入字段中并且单选框勾选了他们最后的选择(默认应该是红色的)。
一旦我尝试加载entry.php,它就会完全空白。top.php很好,但是无论何时单击提交,它都不会去任何地方,只是保持(奇怪和随机?)缩进 textarea 中的默认字符串。
无限的荣誉,并提前感谢大家!
源代码:
(入口.php)
<?php
if($_POST){
$rchecked = "";
$ychecked = "";
$bchecked = "";
$errormsgs = [];
$valid = true;
if(!preg_match("/^[-a-zA-Z0-9' ]{1,50}$/", $_POST['btitle'])){
$errormsgs += "Your a need to fill in a blog title
that is no longer than 50 characters with only these
acceptable characters: Upper/lower case letters, spaces,
hyphens, and digits!";
$valid = false;
}
if(!preg_match("/^[-a-zA-Z0-9<>' ]{1,500}$/", $_POST['bentry'])){
$errormsgs += "You blog entry can't be empty or filled with
only spaces, and can only use upper or lower case letters,
spaces, hyphens, single quote marks, <> and digits. Lastly, it
can't exceed 500 characters in length.";
$valid = false;
}
if($valid){
?>
<table border="1">
<font color="<?php echo $_POST['color']; ?>">
<tr>
<td>Blog Title:</td>
<td><?php echo $_POST['btitle']; ?></td>
</tr>
<tr>
<td>Blog Post:</td>
<td><?php echo $_POST['bentry']; ?></td>
</tr>
</font>
</table>
<?php
}
else{
include('top.php');
function selected($rchecked, $ychecked, $bchecked){
if ($_POST['color'] == "") $rchecked = "checked";
if ($_POST['color'] == "Yellow") $ychecked = "checked";
if ($_POST['color'] == "Blue" ) $bchecked = "checked";
}
}
}
?>
(top.php)
<?php include 'header.php' ?>
<font color=#EEEED1>
<form method="POST">
<center>
Your Blog Title:
<input type=text name=btitle value="<?php echo $_POST['btitle'] ?>" ><?php echo $errormsgs[0]; ?><br>
<textarea name=bentry cols="80" rows="20">
<?php echo isset($_POST['bentry']) ? $_POST['bentry'] : "What's on your mind?"; ?>
</textarea><br><br>
<?php echo $errormsgs[1]; ?>
<table class="t1">
<tr><td>
<input type=radio name=color value="Red" <?php echo $rchecked; ?> ><font color="Red"> Red</font>
</td></tr>
<tr><td>
<input type=radio name=color value="Yellow" <?php echo $ychecked; ?> ><font color="Yellow"> Yellow</font>
</td></tr>
<tr><td>
<input type=radio name=color value="Blue" <?php echo $bchecked; ?> ><font color="Blue"> Blue</font><br><br>
</td></tr>
</table>
<input type=submit value="Create Blog!">
</center>
</form>
</font>
<?php include 'footer.php' ?>