llizard
10-28-2005, 06:18 AM
I have set a limit of 300 characters for a textarea in a form. I'm trying to echo an error message if someone puts too many characters into the textarea. Knowing not all that much about php or programming, I have been trying unsuccessfully to use strlen
$comment = substr(trim($_POST['comment']), 0, 300);
$fixcomment = htmlentities($comment, ENT_QUOTES);
// require comment
if (($comment == "") || (strlen($comment) < 1) || (strlen($comment) > 300))
{
echo '<p class="error">Your <i>Brief</i> Message (required) - use <big>ctrl + ←</big> to go back to edit your message:<br /> <textarea name="comment" id="comment"></textarea></p>';
}
else {
echo '<p>Your Brief Message:<br />
<textarea name="comment" id="comment">' , $fixcomment , '</textarea></p>';
}
I've also tried
if (($comment == "") || (strlen($comment) > 300))
and
if ((strlen($comment) < 1) || (strlen($comment) > 300))
and
if ((strlen($comment) < 0) || (strlen($comment) > 300))
with the same lack of success. If more than 300 characters are typed into the textarea, the form processes and cuts off the message without throwing an error.
Any ideas on where I have made the mistake(s)?
I hope my question made sense.
$comment = substr(trim($_POST['comment']), 0, 300);
$fixcomment = htmlentities($comment, ENT_QUOTES);
// require comment
if (($comment == "") || (strlen($comment) < 1) || (strlen($comment) > 300))
{
echo '<p class="error">Your <i>Brief</i> Message (required) - use <big>ctrl + ←</big> to go back to edit your message:<br /> <textarea name="comment" id="comment"></textarea></p>';
}
else {
echo '<p>Your Brief Message:<br />
<textarea name="comment" id="comment">' , $fixcomment , '</textarea></p>';
}
I've also tried
if (($comment == "") || (strlen($comment) > 300))
and
if ((strlen($comment) < 1) || (strlen($comment) > 300))
and
if ((strlen($comment) < 0) || (strlen($comment) > 300))
with the same lack of success. If more than 300 characters are typed into the textarea, the form processes and cuts off the message without throwing an error.
Any ideas on where I have made the mistake(s)?
I hope my question made sense.