I need to apply the style and read-only property to the input element of the drupal form. I encoded the following:
$form['precio'] = array( '#type' => 'textfield', '#title' => t('Precio'), '#default_value' => ''.$precio, '#size' => 20, '#required' => TRUE, '#attributes' => array($inputAtributo => 1), '#description' => t('Modifica el precio '), );
And with '#attributes' => array($inputAtributo => 1),
Before creating the form, I check if this input should be read-only and apply some style:
if ($tarifa !='' & $tarifa=='N') $inputAtributo=" readonly style=\"background: none repeat scroll 0 0 #EAEAEA;\" "; else $inputAtributo = "";
This works, but I think it is not encoded correctly
The html code shows the following:
<input id="edit-precio" class="form-text required" type="text" maxlength="128" size="20" value="258" name="precio" ="1"="" style="background: none repeat scroll 0 0 #EAEAEA;" readonly="">
How can I do it better?
drupal drupal-7 drupal-fapi
Daniel Diaz
source share