You can truncate a string variable to whatever length you like by using substr.
substr($text_field, 100) = '' if length($text_field) > 100;
will truncate $text_field to 100 chars. Or you could have your program just abort if it received an oversized field.
Caution: Contents may have been coded under pressure.
| [reply] [d/l] [select] |
Aborting with a not so subtle err msg would be the way to go.
Point would be that legit users prob would follow directions, (well, fairly well) and the more time spammers have to waste reading and responding to windy err msg's the better!
I've not used substr, how can it be written to generate an err msg if the length exceeds X chars?
Thx,
Mike
| [reply] |
You wouldn't use substr to generate an err msg. You'd check length of whatever variable shouldn't be too long, and if it exceeded your limit, you'd have the program die or just not call the code that inserts the information into your data store, and generate a page that informs the user that the data they entered was rejected.
if (length($var) > 30) {
# Generate rejection message
}
else {
# Insert data
# Generate success message
}
Caution: Contents may have been coded under pressure.
| [reply] [d/l] |