you type something and hit submit.
it validates that the code is right.
if it's wrong, it changes a variable and refreshes.
when it refreshes, a few if statements decide what goes where etc.
My problem is getting it to refresh right. There's got to be a better way of doing this, but I can't figure it out. Btw, the $testing variable I'd rather have as the $submit variable. In other words, I'd rather $submit = "Errors" if that makes any sense. Here's the entire code with nonessential parts (css, html formatting, etc) taken out:
OH, and wherever {something} is, it's really the square brakets.
Code: Select all
<?php
$page = (isset($_REQUEST['page'])) ? $_REQUEST['page'] : "";
$quote = (isset($_REQUEST['quote'])) ? $_REQUEST['quote'] : "";
$submit = (isset($_REQUEST['submit'])) ? $_REQUEST['submit'] : "";
$testing = (isset($_REQUEST['testing'])) ? $_REQUEST['testing'] : "";
?>
<!--misc stuff-
-body:-->
<?php
if ($page == "random" || $page == NULL) { print('Random Quote'); }
else if ($page == "all") { print('Quote List'); }
else if ($page == "add") {
if ($testing == "Errors") { print ('Errors Found'); }
else {
if ($submit == NULL) { print ('Add a Quote'); }
else if ($submit == "Preview") { print ('Preview'); }
else if ($submit == "Submit") { print ('Quote Added'); }
}
}
?>
<!--misc stuff-->
<?php
if ($page == "all") {
$qblah = file_get_contents("test.txt");
print('<pre>' . str_replace("(%%:)", "\n<div><img src="spacer.gif" alt="" class="spacer" /></div>", $qblah) . '</pre>');
}
else if ($page == "random" || $page == NULL) {
$qblah = file_get_contents("test.txt");
$qlist = explode("(%%:)", $qblah);
$qlength = count($qlist) - 1;
$qrand = rand(1,$qlength);
print('<pre><p>' . $qlist[$qrand] . '</p></pre>');
}
else if ($page == "add") {
if ($submit == "Preview" || $submit == "Submit") {
$qchk = array("" => "", """ => "", "'" => "");
$quote = strtr($quote, $qchk);
$qtb1 = substr_count($quote, "{b}");
$qtb2 = substr_count($quote, "{/b}");
$qti1 = substr_count($quote, "{i}");
$qti2 = substr_count($quote, "{/i}");
$qtu1 = substr_count($quote, "{url=");
$qtu2 = substr_count($quote, "{/url}");
$qtc1 = substr_count($quote, "{color=");
$qtc2 = substr_count($quote, "{/color}");
$qtr1 = substr_count($quote, "{");
$qtr2 = substr_count($quote, "}");
if ($qtb1 != $qtb2 || $qti1 != $qti2 || $qtu1 != $qtu2 || $qtc1 != $qtc2 || $qtr1 != $qtr2) {
################ What goes here? ################
}
else {
$qreal = htmlspecialchars($quote);
$qcng = array("{i}" => "<i>", "{/i}" => "</i>", "{b}" => "<b>", "{/b}" => "</b>",
"{url=" => "<a target="_blank" href="", "{/url}" => "</a>", "{color=" => "<span style="color: ",
"{/color}" => "</span>", "}" => "">",);
$qreal = strtr($qreal, $qcng);
}
}
if ($submit == "Preview") { print('<pre><p>' . $qreal . '</p></pre><div><img src="spacer.gif" alt="" class="spacer" /></div>'); }
else if ($submit == "Submit") {
print('<pre><p>' . $qreal . '</p></pre>');
print('<form><p><input type="button" value="Submit Another Quote" onclick="location=''?page=add''" /></p></form>');
$fp = fopen("test.txt", "a");
fwrite($fp, "(%%:)" . $qreal);
fclose($fp);
}
if ($submit != "Submit") {
print('<form name="addquote"><p><input type="button" value="Bold" onclick="format(''bold'');" />
<input type="button" value="Italics" onclick="format(''italics'');" />
<input type="button" value="URL" onclick="format(''url'');" />
<input type="button" value="Color" onclick="format(''color'');" /></p>
<p><textarea rows="12" cols="80" name="quote">' . $quote . '</textarea></p>
<p><input type="hidden" name="page" value="add" />
<input type="submit" name="submit" value="Preview" />');
if ($submit != NULL) {
print(' <input type="submit" name="submit" value="Submit" /></p></form>');
}
}
} ?>
<!--misc stuff-->