Appnitro Software Forums » MachForm

Limit number of chars per field

(9 posts)

  1. wftsl
    Member

    Hello,

    How can I limit the number of characters per field?

    Best regards

    Posted 2 months ago #
  2. 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 2 months 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 2 months ago #
  4. 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;
    Posted 2 months 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 2 months ago #
  6. Sorry wftsl, I'm afraid that won't be possible.
    Thank you for your suggestion though.

    Posted 2 months 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 1 month ago #
  8. Hi Kmnet,

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

    Posted 1 month ago #
  9. 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 3 weeks ago #

RSS feed for this topic

Reply

You must log in to post.