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

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
texas-bronius's picture

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.png89.61 KB

Comments

a few suggestions

asad.hasan's picture

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

texas-bronius's picture

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?

Silicon.Valet's picture

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

so what it is?

texas-bronius's picture

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

rocketeerbkw's picture

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

Only local images are allowed.

hmm.. code for code?

texas-bronius's picture

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?

hillaryneaf's picture

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

texas-bronius's picture

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