News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Custom field for customer text input lacks maxlength parameter (solved w hack)

Started by t68, September 11, 2013, 23:20:53 PM

Previous topic - Next topic

t68

Hi!
There´s still an issue with the custom field plugin for the customer text input field. Has been there at least since VM2.0.10. The number limitation that you specify in admin for a text input field doesn´t have any effect on the field on the front side.
In our case we want to charge an amount for each letter that a customer wants to put on a piece of jewellery and it´s important that there´s a working limit on the input field, since there´s a limited space to stamp the text on.

When I look at the code on the page the input field gets a "size" parameter with the number specified in admin. But that only affects the width of the field, not the number of characters that can be typed in it.
To get a working character limitation there should be a "maxlength" parameter instead. Or the possibility to use both. Weirdly in our case the size isn´t affected either by the number put here. Maybe the CSS overrides it?

Hope this can be adressed in a future update soon. Should be a pretty easy fix.

And if there is a "quick-and-dirty-fix" to get this working before any update, I would be grateful for any help!

I´m on VM 2.0.22c and J2.5.14

Here´s a product with 3 fields that have 10 as limit in the setting for the custom input field:
http://hullingsilver.se/index.php/2013-01-16-20-12-12/testingtesting/namnbricka-testprodukt-detail

Some info about parameters for input fields
http://www.w3schools.com/tags/att_input_maxlength.asp
http://www.w3schools.com/tags/att_input_size.asp

t68

Guess what! I found out a hack to solve this on my own  :)!

Here´s what I did to get a working character limit on custom fields for customer text input (great if you want to charge by the letter for prints etc without getting to long text strings from customers):

First you put the character limit you want on the custom field in the box labeled "Size of input"

Then you have to edit the php-file in:
Joomla2.5_root_folder\plugins\vmcustom\textinput\textinput\tmpl\default.php

At the top of the code theres this line:
<input class="<?php echo $class ?>" type="text" value="" size="<?php echo $this->params->custom_size ?>" name="customPlugin[<?php echo $viewData[0]->virtuemart_customfield_id ?>][<?php echo $this->_name?>][comment]"><br />

Change the word "size" in to "maxlength" so the code is:
<input class="<?php echo $class ?>" type="text" value="" maxlength="<?php echo $this->params->custom_size ?>" name="customPlugin[<?php echo $viewData[0]->virtuemart_customfield_id ?>][<?php echo $this->_name?>][comment]"><br />

This works for me. I just have one concern and that is if there´s risk of getting problems with the size of the textarea box when there´s no size parameter. But I haven´t noticed that in my shop and with my css. If so I guess I could just add a hard coded size="15" or something.

Hope this can help others and I also hope that a working feature for this will be added in a future update of VM. Preferably so that you can set both max number of characters and size of the box.




insightcreative

Perfect!  This is just what I was looking for as well.

The only caveat I would add is that if you've added all your products with your custom field length set to 25 and you actually only want people to be able to enter 15 then you have to change the value in your custom field AND change the value in each product as it doesn't seem to pull it over if you just change the value in the custom field.

Cheers
Andy
www.mypersonalisedtowels.co.uk

saraheagle

Thanks - helped me out too :)
I used it on the textareainput  /plugins/vmcustom/textareainput/textareainput/tmpl/default.php

and set the maxlength to be the 'Size of input' set on the custom field
<textarea maxlength="<?php echo $params->max_char; ?>" id="...etc..."></textarea>

Studio 42

this hack is not adequate. Because it don't work in all browser and can be bypassed.
You need to check your input on add to cart too, if you need to apply any restriction on user input.