This forum is no longer open and is for reading/searching only.
Please use our new MachForm Community Forum instead.
MachForm Community Forums » MachForm 2
Require a minimum number of characters in a field?
Started 13 years ago by willsffan | 6 posts |
-
Hi,
Is it possible to require that a field contain a minimum number of characters?
Thanks!
Posted 13 years ago # -
This can be done with small customization. If you want to insert this validation on single line text field type. You can edit "includes/post-functions.php" file and go to around line 191 for this code :
$rules[$element_name]['max'] = 255;
Then add these code bellow that line
if ($form_id == 22 && $element_id == 1) { $rules[$element_name]['min'] = 5; }
In there I assume your form id is 22 and the single line text field element id is 1. You need to change those id with yours.
MachForm Support
Posted 13 years ago # -
Awesome! Thanks very much!
Posted 13 years ago # -
What is the proper syntax for the name field element where it is a multi element field...I've tried '_1' and it does not do anything (doesn't break the code but doesn't enforce the rule)
Posted 13 years ago # -
You need to put the custom code on different line number for simple name field. Try to go around line 322 on post-functions.php. You will see these code :
$target_input[$element_name] = $user_input[$element_name];
then you can add this code, exactly above that line
if ($form_id == 22 && $element_name == 'element_1_1') { $rules[$element_name]['min'] = 1; } if ($form_id == 22 && $element_name_2 == 'element_1_2') { $rules[$element_name_2]['min'] = 7; }
that would make you need to put at least 1 character for first name and 7 characters for last name.
MachForm Support
Posted 13 years ago # -
Thanks!!
Posted 13 years ago #
Reply
You must log in to post.