【发布时间】:2012-12-06 18:46:53
【问题描述】:
我需要将样式和只读属性应用于 drupal 表单的输入元素。 我编写了以下代码:
$form['precio'] = array(
'#type' => 'textfield',
'#title' => t('Precio'),
'#default_value' => ''.$precio,
'#size' => 20,
'#required' => TRUE,
'#attributes' => array($inputAtributo => 1),
'#description' => t('Modifica el precio '),
);
'#attributes' => array($inputAtributo => 1),
在创建表单之前,我会检查这个输入是否应该是只读的并应用一些样式:
if ($tarifa !='' & $tarifa=='N')
$inputAtributo=" readonly style=\"background: none repeat scroll 0 0 #EAEAEA;\" ";
else
$inputAtributo = "";
这可行,但我认为它没有正确编码
html代码显示如下:
<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="">
我怎样才能做得更好?
【问题讨论】:
-
作为旁注,传递给
t()的字符串必须是英文的。
标签: drupal drupal-7 drupal-fapi