.php file containing javascript and html
Posted: Tue Feb 03, 2009 5:10 pm
Hi there,
I have downloaded openWYSIWYG editor which I would like to use with a textarea field in a php file. I created an html file and added a textarea field just to check it works and it does. But when I added the same code into the php file (in the html header) it doesn't work.
I don't know much about how php works, the documentation says that openWYSIWYG will work with php but I think I must have to treat the code differently (put it somewhere different?) I don't know.
Any help would be really appreciated.
Thanks
This is the code I put into the php file:
I have downloaded openWYSIWYG editor which I would like to use with a textarea field in a php file. I created an html file and added a textarea field just to check it works and it does. But when I added the same code into the php file (in the html header) it doesn't work.
I don't know much about how php works, the documentation says that openWYSIWYG will work with php but I think I must have to treat the code differently (put it somewhere different?) I don't know.
Any help would be really appreciated.
Thanks
This is the code I put into the php file:
Code: Select all
<html>
<head>
<title>Add New Page Content</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>openWYSIWYG</title>
<link rel="stylesheet" href="docs/style.css" type="text/css">
<!--
Include the WYSIWYG javascript files
-->
<script type="text/javascript" src="scripts/wysiwyg.js"></script>
<script type="text/javascript" src="scripts/wysiwyg-settings.js"></script>
<!--
Attach the editor on the textareas
-->
<script type="text/javascript">
var mysettings = new WYSIWYG.Settings();
mysettings.ImagePopupFile = "addons/imagelibrary/insert_image.php";
mysettings.ImagePopupWidth = 600;
mysettings.ImagePopupHeight = 245;
mysettings.removeToolbarElement("strikethrough");
mysettings.removeToolbarElement("forecolor");
mysettings.removeToolbarElement("backcolor");
mysettings.removeToolbarElement("font");
mysettings.removeToolbarElement("indent");
mysettings.removeToolbarElement("outdent");
mysettings.removeToolbarElement("superscript");
mysettings.removeToolbarElement("subscript");
</script>
<script type="text/javascript">
// Use it to attach the editor directly to a defined textarea
//WYSIWYG.attach('textarea3', small); // small setup
WYSIWYG.attach('thecontent', mysettings);
// Use it to display an iframes instead of a textareas
//WYSIWYG.display('all', full);
</script>
</head>
<?php
// Get the PHP file containing the DbConnector class
require_once('../includes/DbConnector.php');
// 1. Check whether a form has been submitted. If so, carry on
if ($_POST){
// Create an instance of DbConnector
$connector = new DbConnector();
// Start of VALIDATION CODE:
// Gather the data from the form, store it in variables
$pagename = $_POST['pagename'];
$sectontitle = $_POST['sectiontitle'];
$sectionid = $_POST['sectionid'];
$thecontent = $_POST['thecontent'];
// Create a validator object
require_once('../includes/Validator.php');
$theValidator = new Validator();
// Validate the forms
$theValidator->validateTextOnly($pagename, 'Illegal character entered. Please enter only letters a-z or numbers');
$theValidator->validateTextOnly($sectontitle, 'Illegal character entered. Please enter only letters a-z or numbers');
$theValidator->validateTextOnlyNoSpaces($sectionid, 'Illegal character entered. Please enter only letters a-z or numbers with no spaces.');
$theValidator->validateGeneral($thecontent, 'You did not enter any text.');
//2. Start of validator if
if ($theValidator->foundErrors() ){
// The were errors, so report them to the user
echo 'There was a problem with: '.$theValidator->listErrors('<br>'); // Show the errors, with a line between each
}else{
// All ok, add the page content.
// ** Start of add content code: **
// Create an SQL query (MySQL version)
$insertQuery = "INSERT INTO tblpagecontent(pagename,sectiontitle,sectionid,thecontent) VALUES (".
"'".$_POST['pagename']."', ".
"'".$_POST['sectiontitle']."', ".
"'".$_POST['sectionid']."', ".
"'".$_POST['thecontent']."')";
// Save the form data into the database
if ($result = $connector->query($insertQuery)){
// It worked, give confirmation
echo '<center><b>Page content added to the database</b></center><br>';
}else{
// It hasn't worked so stop. Better error handling code would be good here!
//exit('<center>Sorry, there was an error saving to the database</center>');
die ("Error: " . mysql_error());
}
// ** End of add content code. **
} //end of validator if (2)
} //end of check if form was submitted if (1)
?>
<body>
<form name="form1" method="post" action="newArticle.php">
<p> Page Name:
<input name="pagename" type="text" id="pagename">
</p>
<p> Section Title:
<input name="sectiontitle" type="text" id="sectiontitle">
</p>
<p> Section ID:
<input name="sectionid" type="text" id="sectionid">
</p>
<p> Page Content:
<textarea id="thecontent" name="thecontent" cols="50" rows="6">
</textarea>
</p>
<p align="center">
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>