1

我正在尝试从 Drupal 的FileField输出中删除“大小”属性。现在,它输出如下标签:

 <input type="file" name="files[image]"  class="form-file" id="edit-image" size="40" />

unset()我尝试了在自定义模块中的回调中使用的多种排列方式#pre_render,但最终以 size="" 结束。该属性本身永远不会消失,因此 HTML5 验证器继续抱怨。是否有另一种方法可以实现这一点,或者有一种方法可以真正确保您的回调最后运行?$form['mystuff'][] = 'mycallback'没有做到这一点,而普通的老unset($form['mystuff']['#size'])跑得太晚了。

4

1 回答 1

1

Have you tried hook_form_alter()?

function YOUR_THEME_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'YOUR_FORM_ID') { // Selects the form you want        
    $form['YOUR_FIELD_NAME']['#size'] = NULL;
  } 
}

With this I've been able to remove size and add HTML5 bits like placeholders etc:

$form['name']['#attributes'] = array('placeholder' => t('username'));
于 2012-03-05T10:15:38.473 回答