Sometimes it may be useful to set minimum length of the filed. Especially for textareas. This is example for profile editing page. Let's say we want minimum 5 words for every textarea field.
Open your lib.account_profile.php, function save_member(), line ~464 (Validate value conditions)
Right after:
elseif ($field['field_maxlength'] && strlen($field['field_value']) > $field['field_maxlength'])
{
$TEMPLATE->set_message("error", str_replace("%1%", $field['field_name'], str_replace("%2%", $field['field_maxlength'], ($LANG['profile']['field_too_long']))), 0, 0);
return 0;
}
Add this:
elseif ($field['field_type'] == 'textarea' && $field['field_required'] && str_word_count($field['field_value']) < 5)
{
$TEMPLATE->set_message("error", str_replace("%1%", $field['field_name'], str_replace("%2%", 5, ($LANG['profile']['field_too_short']))), 0, 0);
return 0;
}
Now we have to add language string to /includes/languages/english/lang.lib.account_profile.php
right below "field_too_long" translation:
"field_too_short" =>
"\"%1%\" has to contain at least %2% words.",
Voila!
P.S.: If you still want to count only chars, use strlen function instead of str_word_count.
P.P.S.: That was controlling number of words for textareas in Edit profile page. If you want control words number during registration modify lib.account_register.php page!







Comments
slinky
slinky
radioact
radioact
sexcenter
sexcenter
rombest
radioact
Pages
1 2Log in to leave a comment