July 12, 201115 yr I was wondering how i could set a max (500) and min (20) characters allowed for my posting/message system. code for this <div class='submit'> <form method="post" action="newthread.php">LAD Name: <input name="author"/><br/>Message:<br/> <textarea rows="5" cols="60" name="message"></textarea><br/> <input value="Post Banter" type="submit"/> </form> </div> PLEASE NOTE I CAN NOT CHANGE 'NAME' AS IT BREAKS MY PHP CODE FOR POSTING TO DATABASE i tried a script i found on net but when i used this it broke my writing to database. So can someone please tell me how i can set max/min characters allowed and to display error message if these are not met
July 12, 201115 yr I was wondering how i could set a max (500) and min (20) characters allowed for my posting/message system. code for this <div class='submit'> <form method="post" action="newthread.php">LAD Name: <input name="author"/><br/>Message:<br/> <textarea rows="5" cols="60" name="message"></textarea><br/> <input value="Post Banter" type="submit"/> </form> </div> PLEASE NOTE I CAN NOT CHANGE 'NAME' AS IT BREAKS MY PHP CODE FOR POSTING TO DATABASE i tried a script i found on net but when i used this it broke my writing to database. So can someone please tell me how i can set max/min characters allowed and to display error message if these are not met try <textarea rows="5" cols="60" maxlength="500" name="message"></textarea> im not too sure whether minlength is something you could apply to a input field, check the length using php Edited July 12, 201115 yr by web-itec
July 12, 201115 yr Author try <textarea rows="5" cols="60" maxlength="500" name="message"></textarea> im not too sure whether minlength is something you could apply to a input field, check the length using php This doesnt do anything. I tested it with a short value and text was still inputted to database
July 12, 201115 yr maxlength is an attribute of INPUT not TEXTAREA. You need to code some javascript magic to add a maxlength to TEXTAREA and minlength to either INPUT and TEXTAREA. Do a google for the bassistance jQuery validation plugin which does exactly what you need with little effort.
July 12, 201115 yr Size and cols for form input and textarea code limits the size of the box on the screen. The user's input can be any length unless you use PHP to code the form and then you can limit the characters. It would be something like $wordcount = str_word_count($message); if ($wordcount >50) { echo "Please do not exceed fifty words."; } for counting words or another code for characters. The above would have to be tailored to suit a PHP form and might use else or elseif and we don't know what the rest of your PHP process code is. Edited July 12, 201115 yr by Wickham
July 12, 201115 yr Size and cols for form input and textarea code limits the size of the box on the screen. The user's input can be any length unless you use PHP to code the form and then you can limit the characters. It would be something like $wordcount = str_word_count($message); if ($wordcount >50) { echo "Please do not exceed fifty words."; } for counting words or another code for characters. The above would have to be tailored to suit a PHP form and might use else or elseif and we don't know what the rest of your PHP process code is. Something like this IMO would be better done on client side, then backed up on server side. I'd be pissed off if I spent 10 minutes filling in a textarea submitting the form and then being told I was only supposed to write 10 chars. Also I think the OP is looking to count letter count, not word count.
Create an account or sign in to comment