PDA

View Full Version : JS/PHP textarea not working


harlequin2k5
10-15-2006, 03:46 AM
I don't know how to even tell you what the problem is

I'm attempting to use a js wysiwyg text editor (http://www.dynamicdrive.com/dynamicindex16/openwysiwyg/index.htm) on my form...the form won't submit if all the fields aren't filled in and I think it's not recognizing the wysiwyg

I'd post code but I'm not sure what you need...

CFMaBiSmAd
10-15-2006, 04:08 AM
Start by posting your form code. Someone can look at it to see what you are doing and/or try it to see what it is or is not doing.

You are probably using the POST method on the form, put the following in to your action= processing .php file to display what is actually being submitted -
echo "<pre>";
print_r($_POST);
echo "</pre>";

harlequin2k5
10-15-2006, 04:16 AM
I used the <pre> and it displayed data in all the fields

form code:

<form action="<? echo $_SESSION['PHP_SELF'] ?>" method="post">
<p>
<label for="author">Author: </label>
<input type="text" size="40" name="PostAuthor" value="<? echo (isset($_POST['PostAuthor'])) ? $_POST['PostAuthor'] : ''; ?>" />
</p>
<p>
<label for="title">Title: </label>
<input type="text" size="40" name="PostTitle" value="<? echo (isset($_POST['PostTitle'])) ? $_POST['PostTitle'] : ''; ?>" />
</p>
<p>
<textarea id="msgarea" name="PostComment" rows="15" cols="45" value="<? echo (isset($_POST['PostComment'])) ? $_POST['PostComment'] : ''; ?>"></textarea>
<script type="text/javascript">
generate_wysiwyg('msgarea');
</script>
</p>
<p>
<input type="submit" name="add" value="Add Comment" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" name="reset" value="Start Over" />
</p>
</form>


the php code is:
$author=$_POST['PostAuthor'];
$title=$_POST['PostTitle'];
$content=$_POST['PostContent'];
$error=array();

if (isset($_POST['add']))
{

if (strlen(trim($_POST['PostAuthor']))==0)
{
$error['author'] = 'Please enter your name.';
}

if (strlen(trim($_POST['PostTitle']))==0)
{
$error['title'] = 'Please enter a title.';
}

if (strlen(trim($_POST['PostContent']))==0)
{
$error['content'] = 'Please enter a comment.';
}

if (count($error)==0)
{
$query="INSERT INTO tblSCIBlog (PostDate, PostAuthor, PostTitle, PostContent) VALUES (CURRENT_DATE(), '$author', '$title', '$content')";
$result=mysql_query($query);

if($result)
{
echo "<p style=\"color:#ff0000;font-weight:bold;font-size:14px;\">Your blog entry has been submitted.</p>";
}
mysql_close($conn);
}

else
{
foreach($error as $err)
{
echo "<p style=\"color:#ff0000;font-weight:bold;font-size:14px;\">" . $err . "</p>";
}
}

}

harlequin2k5
10-15-2006, 04:20 AM
n/m I'm using the wrong variable again

these variables are going to kill me!

using PostComment instead of PostContent

CFMaBiSmAd
10-15-2006, 04:37 AM
Edit: Took me a while to test... and type. I see you found it.

I see one problem right away - the following:

$_SESSION['PHP_SELF'] should probably be $_SERVER['PHP_SELF']

However, it evaluates to a null/empty and results in an action="" which submits back to the same file anyway.

It tried your code (less the javascript) and here is where the most obvious problem is -

The content field on the form has the name - PostComment
However, the $_POST variable has the name - PostContent