Forum Moderators: phranque
Which do you have available to you? I (or anyone else here) would be glad to post code you could work with.
I'm on hosts that support PHP. Will the code stop the scrolling or, will it only pull a certain amount of text out of the area? It does seem like an obvious necessity. Another lovely aspect of text areas is the cross browser problems. NN adds columns to the area and, scrolls linearly (I spent an hour trying to get it to scroll vert but, it seems you have to work it like a typewriter). I figured the text areas were going to be the easy part.
I've been toying with events/behaviors. There seems to be some in them for altering content. Any use in them for what I'm trying to do? Thanks for your time,
TJ
e.g.
$text_field = $_POST["text_field"];
$max_length = 200;// To let the user enter something else
if(strlen($text_field > $max_length))
{
// return an error
}// To just clip the excess
if(strlen($text_field > $max_length))
$text_field = mid($text_field,0,$max_length);
Either will work, but from the user perpective, the prior is best because that way they *know* what data they'll end up passing.
The reason I say that server side validation is the only way to ensure it is because people can always spoof with your HTML if they want to. Unless your form processing script is very strict about checking referrers, browser types and version, and all that stuff (which is all spoofable anyhow) your best bet is to check everything behind the scenes.
Javascript Validation - Can be disabled or removed from a page
Database limits - This is good practice anyway, but it won't solve any problems. Most database systems will fail if you try to enter too much information into a field (rather than just cutting it off and returning a successful operation).
Plus, if it were to just cut off the text, that would be a poor usability standard to operate under. You want users to know what's being stored (that is, exactly what they type). If it's too much text, tell them so so they can alter what they entered to make it right.
I try to use a combination of three things when I have time to do so, but only server side validation is necessary:
1. HTML limits on text fields (arg, but doesn't work on <textarea>
2. OnSubmit or onBlur validation (I prefer onSubmit for less code, but onBlur for less hassle on the user end)
3. Server side validation
It's a little bit more work, but it will cut down on errors dramatically.