22 replies [Last post]
jimi089's picture
Offline
Uber Donor
Joined: 09/07/2007
Juice: 219
Was this information Helpful?

Greetings fellow Ubercarters,

So my site is up and running with one issue now that I need to tackle. I had an attribute for each product so people can type in a gift message. However, there appears to be a character limit on that box that makes it not quite long enough to suit that purpose.

How can I change that character limit?

As a related question, do you all think this might make more sense as a box in the checkout rather than with the product?

Thanks!

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: Attribute text box

I didn't think there was a hard character limit on the attribute text fields. Might be a browser limitation, or I haven't looked hard enough yet.

Making a checkout pane for gift messages would allow you to have more control over how it's presented and stored in the order. There's already the Order Comments pane that can serve in that capacity as well.

jimi089's picture
Offline
Uber Donor
Joined: 09/07/2007
Juice: 219
Re: Re: Attribute text box

Thanks for the info Lyle. There does appear to be a character limit on the attribute text field, FWIW.

I actually tested making the Order Comments pane a Gift Message pane, but was having some issues with it that I haven't had the time to figure out.

jimi089's picture
Offline
Uber Donor
Joined: 09/07/2007
Juice: 219
Re: Re: Re: Attribute text box

It looks like the attribute box has a maxlength="128" on the text box that comes up in multiple browsers when I look at the page source. Is there any way to change that ? Any idea where it's being generated? I don't see anything in uc_attribute. I wonder if there's some kind of default in Drupal's generating of text boxes that I need to alter.

Okay, I'm now trying to make a theming function that will alter this. However, apparently this isn't my forte! Anyone have an idea as to why this isn't working?

function attribute_form_alter($form_id, &$form)  {
  if($form_id == "attributes-8") {
    $form['title']['#maxlength']= 256;
  }
}
?>
oslinux's picture
Offline
Joined: 09/06/2007
Juice: 461
Re: Re: Re: Re: Attribute text box

Thought: Maybe altering it directly at the sql table?

Anyhow, how do you process this field anyhow later on? Thus you could sort of store it in your own table and then pull it out with a cck computed field ...

jimi089's picture
Offline
Uber Donor
Joined: 09/07/2007
Juice: 219
Re: Re: Re: Re: Re: Attribute text box

OSLinux: would altering it directly at the SQL table change the fact that it's being limited in size by the input type maxlength in the HTML? If so, how would you do that?

It's processed as an attribute, so it shows up with the product that was ordered.

oslinux's picture
Offline
Joined: 09/06/2007
Juice: 461
Re: Re: Re: Re: Re: Re: Attribute text box

My initial thought was that sql can carry more, hence Drupal restricted it to begin with, right? I may be wrong here, but maybe only drupal cares for the limit during creation and then leaves it to the db settings which you now could alter back.

But why don't you go and make the gift order text appear during check out in a big field (pane hook, see lead tracker example on livetest demo here), since one would normally put a greeting to an order and not only to an item. That is why I have asked why you need it with the direct item in the first place ..

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: Re: Re: Re: Re: Re: Re: Attribute text box

Even if the database column can hold 255 characters (and that's what it's set to, not 256), the HTML that is output by Drupal can still cause the browser to prevent more than 30 characters from being put into the form element. The two layers don't have anything to do with each other.

jimi089's picture
Offline
Uber Donor
Joined: 09/07/2007
Juice: 219
Re: Re: Re: Re: Re: Re: Re: Re: Attribute text box

Thanks for your help Lyle!

oslinux's picture
Offline
Joined: 09/06/2007
Juice: 461
Re: Re: Re: Re: Re: Re: Re: Re: Attribute text box

i believe you (now) ..

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: Re: Re: Re: Attribute text box

oslinux, the maxlength of a form element has nothing to do with the database.

jimi, the $form_id isn't the HTML id attribute, but the value of the form_id hidden form element. For the add to cart form, it should be 'uc_product_add_to_cart_form'. Try doing

<?php
 
foreach (element_children($form['attributes']) as $element){
    if (
$element['#type'] == 'textfield'){
     
$element['#maxlength'] = 256;
    }
  }
?>

to get all of the attribute textfields that might show up. If you have product kits, you'll need to handle that form separately because it's structured differently.

I finally found where it was coming from: system_elements() in system.module.

Infinitee's picture
Offline
Joined: 02/19/2010
Juice: 78
Where does this go?

Hi Lyle,

Exactly where would I put this nice little tid bit and would this work as well?

<?php
   
foreach (element_children($form['attributes']) as $element){
        if (
$element['#type'] == 'textfield'){
           
$element['#maxlength'] = 256;
           
$element['#size'] = 30;
           
$element['#rows'] = 4;
        }
    }
?>

Thanks,

Ralph

Ralph Manis
Infinitee Web Design
http://www.infiniteewebdesign.com

bhallnc's picture
Offline
Joined: 03/23/2009
Juice: 81
Re: Where does this go?

If you need to limit the attribute text length for each product, try this: http://drupal.org/project/uc_attribute_length

We just recently had it ported to D6 and it works great.

Infinitee's picture
Offline
Joined: 02/19/2010
Juice: 78
Mainly interested in the size="30"

I have a text field for customers to input personalized text to be added to a greeting card. But, the default the size="60" is way to wide for the catalog table columns.

The $element['#rows'] = 4; would just be for aesthetics.

Thanks,

Ralph

Ralph Manis
Infinitee Web Design
http://www.infiniteewebdesign.com

nadavoid's picture
Offline
Joined: 11/13/2007
Juice: 63
How?

I'm trying to add a plain text attribute, where a person can enter their name or phone number, to personalize the product. What did you use to add your text attribute? The only attributes I'm able to add so far are select lists.

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: How?

Just don't add any options to the attribute and it will be a textfield. Smiling

nadavoid's picture
Offline
Joined: 11/13/2007
Juice: 63
Ubercart and Drupal are making me happy

Oh. My. Gosh. Wow. Umm, that was easy.

sprugman's picture
Offline
Joined: 11/26/2007
Juice: 202
Re: Re: How?

Is it possible to make the attributes required?

nickgs's picture
Offline
Joined: 02/25/2008
Juice: 113
Re: Re: Re: How?

Sprugman, you can make an attribute required by selecting the 'required' check box after tagging an attribute to a product.

KillerJerseys's picture
Offline
Joined: 01/17/2008
Juice: 58
Re: Attribute text box

Sorry for bringing up an older topic! I'm trying to do the opposite of what the threadstarter wants to do:

I have 2 attribute text boxes:
Name (maximum 12 characters)
Number (maximum 2 characters)

Do I need to edit core files to change specific Attribute's textbox size? If so, where?

uberguy's picture
Offline
Joined: 02/24/2009
Juice: 22
Hi KillerJerseys,Have you

Hi KillerJerseys,

Have you find out the way to limit the size of the ubercart product attribute length? I am on Drupal 6.9 and Ubercart 2.x beta3
Any follow up on this? I try to implement custom module using hook_form_alter but could not find out the attribute, in my case, it is attribute[6], but how to find out this so that the size can be changed.

I have been going through hook_form_alter but there is no example on changing the additional Ubercart product attributes like name text or in your case, the jersey number.

Sorry for bringing up the old issue again.

Thanks.

cha0s's picture
Offline
Getting busy with the Ubercode.
Joined: 08/22/2008
Juice: 416
Re: Hi KillerJerseys,Have you

There's this http://www.ubercart.org/contrib/5341, but I think it's only for Drupal 5.

Try FreeBASIC!
My game Lynn's Legacy

jasonabc's picture
Offline
Uber Donor
Joined: 05/05/2008
Juice: 573
Re: Re: Hi KillerJerseys,Have you

this was recently ported to D6 and works very nicely:

http://drupal.org/project/uc_attribute_length