News:

Support the VirtueMart project and become a member

Main Menu

How can I add a 'maxlength' attribute to the custom field input plugin?

Started by riverhawk, March 06, 2012, 22:39:48 PM

Previous topic - Next topic

riverhawk

I have a product with the custom input plugin working, but I want to limit the amount the user is able to input. This isn't a CSS attribute so I'm guessing I have perform a template override in the productdetails view. Just not sure which php file to modify and if I should put some conditionals around it such as 'if product-fields-title = 'my limited input'' then maxlength=100...or something similar.

I'm 0-3 on on forum post answers. Hoping for the best. Thanks.

riverhawk

After looking at default_addtocart.php in the productdetails view, it looks like it just prints the saved html info(I want to add an HTML attribute to the product-field-display):

<form method="post" class="product js-recalculate" action="index.php" >

<?php // Product custom_fields

if (!empty($this->product->customfieldsCart)) { ?>


    <div class="product-fields">

<?php foreach ($this->product->customfieldsCart as $field) { ?>

    <div class="product-field product-field-type-<?php echo $field->field_type ?>">

<span class="product-fields-title" ><b><?php echo JText::_($field->custom_title?></b></span>

<?php if ($field->custom_tip)

    echo JHTML::tooltip($field->custom_tipJText::_($field->custom_title), 'tooltip.png'); ?>


<span class="product-field-display"><?php echo $field->display ?></span>



<span class="product-field-desc"><?php echo $field->custom_field_desc ?></span>

    </div><br />

    <?php

}

?>


    </div>

<?php


Does this mean I have to hack some administration files when the HTML attributes are being saved/retrieved? Am I close?

I realize this isn't a huge priority for the VM team, but any direction/advice would help. Thanks.

riverhawk

Still haven't found a solution to this. Kind of need this to limit my customer's text input as it is related to what they are buying. Thanks.

PRO

what happens when you choose something for this

"Size of input" in the actual plugin parameter?


riverhawk

That just adjusts the size of the box where you put the input in(the length of it). It affects the actual box size...nothing to do with the input.

bisonfume

I saw this  php topic in this  php forum : http://php.bigresource.com/Virtuemart-preset-product-fields-in-admin-echo-a-standard-value-in-the-input-fields--ogf9hzZln.html

"Virtuemart Preset Product Fields In Admin / Echo A Standard Value In The Input Fields?

If you need to add a product in virtuemart I only use 25% of the products fields. I wish to preset the input fields so I don't have to fill in all the fields. The problem is that the value of the input is a php-code to insert it into the database.

<input type="text" class="inputbox" name="product_name" value="<?php echo shopMakeHtmlSafe( $db->sf("product_name")); ?>" size="32" maxlength="255" />

Is there a way to echo a standard value in the input fields? Without distrubing the connection or make it bug."


Do you think that's the good way to limit the input fields (number of letters) ?

riverhawk

At this point I'm open to hard coding a php statement somewhere just to set the maxlength to 100(or whatever number I want). I attached a snipit of me inspecting the element. It's a customfield of type 'E', but I can't find where the html is printed and/or saved in the DB to be printed later. I've tried a lot of different places and files, but can't find where to place my 'maxlength="100"' add-in.



[attachment cleanup by admin]

ArtRight

Hello!

on line 83 of textinput.php, within the <input> add:

maxlength="'.$field->custom_size.'"

This will automatically set the maxlength to the "size of input" that you specify in the admin backend.  You could of course also use a hard number to make all uses of the plugin the same, for example <input type="text" maxlength="20">

I am still having one other problem with this plugin... if a customer adds more than one of the same product SKU with different custom text, they are all the same price in the shopping cart.  it displays the different custom text attributes correctly, but makes the prices all the same as the first one added to the cart.

http://artright.biz/our-online-shop/another-type-of-frames/word-mats/custom-word-letter-mat-for-3-x5-photos-detail.html