Attribute text box

Posts: 104
Joined: 09/07/2007
Uber Donor

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!

Posts: 2244
Joined: 08/07/2007
AdministratoreLiTe!

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.

Posts: 104
Joined: 09/07/2007
Uber Donor

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.

Posts: 104
Joined: 09/07/2007
Uber Donor

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;
  }
}
?>

Posts: 203
Joined: 09/06/2007

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 ...

Posts: 104
Joined: 09/07/2007
Uber Donor

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.

Posts: 2244
Joined: 08/07/2007
AdministratoreLiTe!

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.

Posts: 203
Joined: 09/06/2007

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 ..

Posts: 2244
Joined: 08/07/2007
AdministratoreLiTe!

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.

Posts: 104
Joined: 09/07/2007
Uber Donor

Thanks for your help Lyle!

Posts: 203
Joined: 09/06/2007

i believe you (now) ..

Posts: 6
Joined: 11/13/2007

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.

Posts: 5269
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

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

Posts: 6
Joined: 11/13/2007

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

Posts: 68
Joined: 11/26/2007

Is it possible to make the attributes required?

Posts: 14
Joined: 02/25/2008

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

Posts: 27
Joined: 01/17/2008

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?