Been staring at this all night and I can't seem to figure out where it's going wrong. Basically I have implemented a content management system tutorial I found. I want to add tinyMCE so users of the system can post articles or whatever and allow them a bit of customisation, it worked fine previously, now i've added tinyMCE, the information in one section does not seem to be passed in. Is there something stupid I am missing? I realise the pagebody textbox isn't assigned a value but I tinkered with that and had no joy. A point in the right direction would be very much appreciated. The textarea in question is called 'pagebody,' here is my code:
This is to create a new page with the information provided but it fails when the user clicks the 'create new page' button. It hits the validate alert button. I removed a filter on another page which allowed me to create the new page, but the element used to hold the pagebody text was empty despite me entering data. Here is the parse page the form is submitted to:
Code:
<?php
session_start();
include_once "admin_check.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
<title>Creating New Page</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<!-- OF COURSE YOU NEED TO ADAPT NEXT LINE TO YOUR tiny_mce.js PATH -->
<script type="text/javascript" src="../tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({
mode : "textareas",
theme : "advanced",
theme_advanced_buttons1 :"save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsizeselect"
});
function validate_form ( ) {
valid = true;
if ( document.form.pagetitle.value == "" ) {
alert ( "Please enter the page title." );
valid = false;
} else if ( document.form.linklabel.value == "" ) {
alert ( "Please enter info for the link label." );
valid = false;
} else if ( document.form.pagebody.value == "" ) {
alert ( "Please enter some info into the page body." );
valid = false;
}
return valid;
}
</script>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
}
-->
</style></head>
<body>
<table width="100%" border="0" cellpadding="8">
<tr>
<td><h3>Creating a New Page • <a href="index.php">Admin Home</a> • <a href="../" target="_blank">View Live Website</a></h3></td>
</tr>
<tr>
<td>Be sure to fill in all fields, they are all required.<br /></td>
</tr>
<tr>
<td>
<table width="100%" border="0" cellpadding="5">
<form id="form" name="form" method="post" action="page_new_parse.php" onsubmit="return validate_form ( );">
<tr>
<td width="12%" align="right" bgcolor="#F5E4A9">Page Full Title</td>
<td width="88%" bgcolor="#F5E4A9"><input name="pagetitle" type="text" id="pagetitle" size="80" maxlength="64" value="<?php echo $pagetitle; ?>" /></td>
</tr>
<tr>
<td align="right" bgcolor="#D7EECC">Link Label</td>
<td bgcolor="#D7EECC"><input name="linklabel" type="text" id="linklabel" maxlength="24" value="<?php echo $linklabel; ?>" />
(What the link to this page will display as)</td>
</tr>
<tr>
<td align="right" valign="top" bgcolor="#DAEAFA">Page Body</td>
<td bgcolor="#DAEAFA"><textarea name="pagebody" id="pagebody" cols="88" rows="16"><?php echo $pagebody; ?></textarea></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="button" id="button" value="Create this page now" /></td>
</tr>
</form>
</table>
</td>
</tr>
</table>
</body>
</html>
This is to create a new page with the information provided but it fails when the user clicks the 'create new page' button. It hits the validate alert button. I removed a filter on another page which allowed me to create the new page, but the element used to hold the pagebody text was empty despite me entering data. Here is the parse page the form is submitted to:
Code:
<?php
// You may want to obtain refering site name that this post came from for security purposes here
// exit the script if it is not from your site and script
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$pagetitle = $_POST['pagetitle'];
$linklabel = $_POST['linklabel'];
$pagebody = $_POST['pagebody'];
// Filter Function -------------------------------------------------------------------
function filterFunction ($var) {
$var = nl2br(htmlspecialchars($var));
$var = eregi_replace("'", "'", $var);
$var = eregi_replace("`", "'", $var);
return $var;
}
$pagetitle = filterFunction($pagetitle);
$linklabel = filterFunction($linklabel);
$pagebody = filterFunction($pagebody);
// End Filter Function --------------------------------------------------------------
include_once "../scripts/connect_to_mysql.php";
// Add the info into the database table
$query = mysqli_query($myConnection, "INSERT INTO pages (pagetitle, linklabel, pagebody, lastmodified)
VALUES('$pagetitle','$linklabel','$pagebody',now())") or die (mysqli_error($myConnection));
echo 'Operation Completed Successfully! <br /><br /><a href="index.php">Click Here</a>';
exit();
?>