codeboy89 Posted November 10, 2009 Share Posted November 10, 2009 Here is the code for my message page and below it the code that posts the message. Can anyone please show me how to add a character limit of 3000 to the message/textarea? message page: <?php // Get the file $file = implode('', file ("post.xml")); print " <form action=post.php method=post> <input type=hidden name=post value=yes> <p> Your Name<br> <input type=text name=name size=30> </p> <p> Message<br> <textarea name=message rows=5 cols=50></textarea> </p> <p> <input type=submit value=\"Post\"> <input type=reset value=Reset> </p> </form>"; ?> action page: <?php $name=$_POST['name']; $message=$_POST['message']; // Name and Message required if (( $name == "") || ( $message == "")) { print "<p align=center>Please go back to complete all fields!<p>"; } else { //Get the file $file_name = "post.xml"; $file_pointer = fopen($file_name, "r+"); $lock = flock($file_pointer, LOCK_EX); $file_read = fread($file_pointer, filesize($file_name)); //$name = strip_tags($name, ''); //$message = strip_tags($message, ''); $date = date ("j M Y"); $post = "\n\n<ponmurt>\n<p><span class=name>$name</span><span class=date> $date</span><br>$message</p>\n</ponmurt>"; //Paste the updated info into the file $post = stripslashes($post); fwrite($file_pointer, "$post"); fclose($file_pointer); print "<head><meta http-equiv=refresh content=0;URL=index.php></head>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/181032-php-error-handling-to-limit-characters-in-textarea/ Share on other sites More sharing options...
.josh Posted November 10, 2009 Share Posted November 10, 2009 if (strlen($string) > 3000) { // longer than 3000 } Quote Link to comment https://forums.phpfreaks.com/topic/181032-php-error-handling-to-limit-characters-in-textarea/#findComment-955157 Share on other sites More sharing options...
codeboy89 Posted November 10, 2009 Author Share Posted November 10, 2009 Would this be the correct way to add it? // Name and Message required if (( $name == "") || ( $message == "")) { print "<p align=center>Please go back to complete all fields!<p>"; } if (strlen($message) > 3000) { print "<p align=center>Too long!<p>"; } else { Quote Link to comment https://forums.phpfreaks.com/topic/181032-php-error-handling-to-limit-characters-in-textarea/#findComment-955170 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.