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

Limit number of chars per field


  1. wftsl
    Member

    Hello,

    How can I limit the number of characters per field?

    Best regards

    Posted 16 years ago #
  2. webcommerce
    Member

    wftsl Hi,

    I too would like to know if there is a 'quick' way to do this, so hoping support has a solution. It would be useful for zip/postcode fields etc.

    You might also check out http://www.dynamicdrive.com/dynamicindex16/ (Form Effects) which has some field limiting scripts. I haven't used any of these but I can say most of their scripts are pretty good (reliable).

    Regards,
    Ron S

    Posted 16 years ago #
  3. wftsl
    Member

    Thanks webcommerce,

    I'd like to know if there is any "out of the box" solution for this problem, as I guess speaking of forms, this is very mandatory.

    Regards,
    wftsl

    Posted 16 years ago #
  4. redityo

    Hi,

    May I know, what element do you want to limit ? if it's all of element, I'm afraid you should do a lot of modification.
    I have an example, in here you want to limit a "text element" in form 1 on element_1. To do that, you have to edit "includes/view-functions.php", try to search between line 40 ~ 47 you will find 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;

    after that replace with this one

    if ($_GET['id'] == 1 && $element->id == 1)
    			$set_max = 'maxlength="10"';
    		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;

    if you want to have all "text element" limited, so you can ignore the "if" condition. It will be like this

    $set_max = 'maxlength="10"';
    
    $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;

    MachForm Support

    Posted 16 years ago #
  5. wftsl
    Member

    Hi and thanks for your reply.

    Can't this be done directly from the form properties with a hack or update of the software?

    There are some forms I need to limit addresses, others I need to limit names, or text boxes, and this seems to be more complicated that what I expected.

    Posted 16 years ago #
  6. yuniar

    Sorry wftsl, I'm afraid that won't be possible.
    Thank you for your suggestion though.


    MachForm Founder

    Posted 16 years ago #
  7. kmnet
    Member

    Hi. I just bought this software. I have a problem getting the text limit based on the above instructions to work. Can you further elaborate the steps?

    I need single line text field to have a maximum characters of only 30. Extremely crucial to my business.

    Thank you.

    Posted 16 years ago #
  8. redityo

    Hi Kmnet,

    I've got your mail, let's continue there


    MachForm Support

    Posted 16 years ago #
  9. microvb
    Member

    Can you not just add something to the $element function.

    Aka:

    $element->max_size; ' Define the maximum amount of characters allowed for input
    $element->min_size; ' Used in validation to ensure the amount of characters is of the min size or greater

    This would be a simple method for accepting variable size input fields with certain size requirements. If the developers of MachForm added this functionality to their "TextField" and "NumberField" data types, this should resolve this problem nicely, also providing a way for people to easily modify the character restrictions.

    Speaking of that, if the developers of MachForm could also add a "Store as String" option to the "NumberField" data type, this would eliminate the problems in receiving values such as 1.26473828998432874+E15 when in fact it was supposed to be a really long number.

    Problem with using the "TextField" data type for input of long numbers is that it does not allow for restricting that field to ONLY accept numbers.

    Posted 16 years ago #
  10. Brainwrap
    Member

    Hi there; I'm attempting to limit the text boxes in my forms to 110 characters. I tried testing your method by swapping out the lines 40-47 with the exact code you suggested (I realize this would limit it to 10, not 110; this is just for testing purposes):

    $set_max = 'maxlength="10"';
    
    $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;

    ...with absolutely no effect whatsoever.

    Does this only impact forms or fields created *after* the code change, or should it impact existing forms/text boxes as well?

    Posted 14 years ago #
  11. yuniar

    Are you sure you are using "Single Line Text" field already? Since the above code would work for that field type only. Using "Number" field won't work.

    The modification should affect all existing forms.


    MachForm Founder

    Posted 14 years ago #

RSS feed for this topic

Reply