My logic has been to try and validate the two text fields (for specifically how, check out the error strings), and use a flag that if turned off reverts the user back to the original form with his most recent data still written in the fields and the radio box checked off to their last choice (default should be red).
As soon as I try to load the entry.php it comes up completely blank. The top.php is fine, but whenever you click on the submit, it doesn't go anywhere and just keeps (weirdly and randomly?) indenting the default string in the textarea.
Infinite kudos and thanks to everyone in advance!
Source Code:
(Entry.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' ?>