Drupal 6 Form API - setting #size doesn't seem to set for me?

Events happening in the community are now at Drupal community events on www.drupal.org.
Posted by texas-bronius on January 13, 2011 at 5:21pm

For some reason my module's form's textfield is not obeying the size => 4 I'm asking it to be. Am I overlooking something (again)?
In addition to the whole code below, see the attached screenshot...

<?php
function project_calc_concrete_calculator() {
$form['instructions'] = array(
'#prefix' => '<p>',
'#value' => t('Enter concrete slab dimensions'),
'#suffix' => '</p>',
);
$form['concrete'] = array(
'#type' => 'radios',
'#title' => t('Pick desired concrete'),
'#options' => array(
'1' => t('80lb Bag of Concrete'),
'0.6' => t('80lb Bag of Regular Concrete'),
'0.5' => t('40lb Bag of Concrete'),
),
'#required' => true,
);
$form['length'] = array(
'#type' => 'textfield',
'#title' => t('Length'),
'#field_suffix' => t('feet'),
'#required' => true,
'#size' => 4,
'#weight' => 1,
);
$form['width'] = array(
'#type' => 'textfield',
'#title' => t('Width'),
'#field_suffix' => t('feet'),
'#required' => true,
'#size' => 4,
'#weight' => 2,
);
$form['depth'] = array(
'#type' => 'textfield',
'#title' => t('Depth'),
'#field_suffix' => t('inches'),
'#required' => true,
'#size' => 4,
'#weight' => 3,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Go',
// '#executes_submit_callback' => false,
'#weight' => 10,
);
$form['msg'] = array(
'#prefix' => '<div id="calc-msg">',
'#value' => t('Enter values, and click Go.'),
'#suffix' => '</div>',
'#weight' => 11,
);
return
$form;
}
?>

results in
<input type="text" class="form-text required" value="" size="" id="edit-length" name="length" maxlength="128">

Thanks
-Bronius

AttachmentSize
drupal-6-fapi-size-empty.png 89.61 KB

Comments

a few suggestions

Posted by asad.hasan on January 13, 2011 at 5:58pm

If i was debugging that i would start by putting the textfields in a form field group instead of have it floating.

"If you have to do a sequence of actions more than twice, they are in the wrong abstraction layer :D" - Learned from drupal

ok that's a potential aesthetic improvement

Posted by texas-bronius on January 13, 2011 at 9:10pm

But is there any change to the functionality? Shouldn't #size be #size no matter where the textfield on which it lies*?

  • it's probably "lay," but really, size size lay? no.. size size lies sounds so nice.

did you ever resolve this?

Posted by Silicon.Valet on January 17, 2011 at 11:30pm

I just use css to size them. #size doesn't matter ;)

so what it is?

Posted by texas-bronius on January 19, 2011 at 9:14pm

Yes, css of course works to fix this aesthetically, but I'm a developer, and it's more unsettling to me that this isn't working (or rather, as a humble developer, important to me to know what I'm doing wrong) than it is to make it look right :)

Works for me

Posted by rocketeerbkw on January 24, 2011 at 5:52pm

I copied your code into a block and got the desired results

Only local images are allowed.

hmm.. code for code?

Posted by texas-bronius on January 26, 2011 at 8:27pm

Thanks for that validation. Doubly confused, but at least now i know it's possible and that the difference must be in how we are doing something different :)..
Not to be pedantic, but if you copied the code 1:1 why is your html with name="" instead of, for instance, name="length"? (just something that stood out which may provide a clue)

solution?

Posted by hillaryneaf on October 28, 2011 at 9:46pm

I have the exact same issue. I have it working just fine on a local installation clone (on wamp), but when I put it on a linux/apache/mysql/php installation it doesn't obey the #size setting.

Did you ever find a solution?

no, never got it working

Posted by texas-bronius on October 30, 2011 at 2:34am

Hi- No, I never got this working (to my knowledge). Moving on, css will do it. Yes, the FAPI looks correct and should do it, and as you discovered, it seems to work in dev but not remotely. Maybe clear cache and look again?
Good luck
-Bronius

AltStyle によって変換されたページ (->オリジナル) /