Pleas explain how I would limit the number of characters allowed in a field. I need to limit certain fields to say 6 or 8 numbers.
Thanks.
Pleas explain how I would limit the number of characters allowed in a field. I need to limit certain fields to say 6 or 8 numbers.
Thanks.
Hi,
To set the limit you need to edit "includes/view-functions.php", for example you want to limit "Text Field" with element id = 1 in form 1, then go around line 40 ~ 50, you will see this code :
$element_markup = <<<EOT
<li id="li_{$element->id}" {$error_class}>
<label class="description" for="element_{$element->id}">{$element->title} {$span_required}</label>
<div>
<input id="element_{$element->id}" name="element_{$element->id}"
class="element text {$element->size}" type="text"
value="{$element->default_value}" />
</div>{$guidelines} {$error_message}
</li>
EOT;
replace the code with this one
if ($_GET['id'] == 1 && $element->id == 1)
$set_max = 'maxlength="8"';
else
$set_max = '';
$element_markup = <<<EOT
<li id="li_{$element->id}" {$error_class}>
<label class="description"
for="element_{$element->id}">{$element->title} {$span_required}</label>
<div>
<input {$set_max} id="element_{$element->id}" name="element_{$element->id}"
class="element text {$element->size}" type="text"
value="{$element->default_value}" />
</div>{$guidelines} {$error_message}
</li>
EOT;
those code will limit text field size to 8
Excellent. Thanks Redityo.
Hi,
I've used the above code to set the character limit to 50 for a text area but it still allows the input of more characters.
Also, I have a number of text areas in my form that must be limited to 50 characters. Is there a way that I could have a default set for all text areas in form_1 for instance?
Many thanks
Hi,
Have you change the form id and element id with yours in these code ?
if ($_GET['id'] == 1 && $element->id == 1)
$set_max = 'maxlength="8"';
else
$set_max = '';
Anyway if you need to apply the code in all text field on form 2 for example, you can change those condition to be like this :
if ($_GET['id'] == 2)
$set_max = 'maxlength="8"';
else
$set_max = '';Here's a question: I am integrating my form (id = 4) using the Advanced Code method (which does a php include), so the above code does not work because it is trying to $_GET the form ID and element ID from the url. My question is how can I limit the characters in a field when using the Advanced Code Form method?
My form id is 4. I would like to limit element_id 9 and 10 to 4 characters and element_id 19 to 16 characters.
Thank you!!
I see... advance embed code have different approach indeed. I think the easy way by editing "includes/post-functions.php" file to set a maximum input validation, so when the user input exceed maximum length, it'll show the error. To do so, go to around line 165 and you will see this code :
$rules[$element_name]['max'] = 255;
put these code exactly bellow that line
if ($form_id == 4 )
{
if ($element_id == 9 || $element_id == 10)
$rules[$element_name]['max'] = 4;
elseif ($element_id == 19)
$rules[$element_name]['max'] = 16;
}
Otherwise you can change my previous code, by adding a session variable in your PHP page. Add these code to your PHP page after "<?php"
@session_start();
$_SESSION['sess_form_id'] = 12;
then change my previous code from :
if ($_GET['id'] == 2)
$set_max = 'maxlength="8"';
else
$set_max = '';
to
if ($_SESSION['sess_form_id'] == 2)
$set_max = 'maxlength="8"';
else
$set_max = '';You must log in to post.