欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

drupal 文本字段禁用

shiping1 的头像

how to make a textfield un editable?

I have a text field which displays the username. The user should not be able to edit the text field values. Can anyone help me on this?

Thanks,
Sagar.

Comments

Where exactly does this field appear?

If it's the one in the profile page, you should go to the permissions settings and un-check the relevant permission.

Hi,

You could try adding one of the following attributes to your text field:

  $form['username'] = array(
    '#type' => 'textfield',
    '#title' => t('username'),
    '#attributes' => array('readonly' => 'readonly'),
  );

http://www.w3.org/TR/html4/interact/forms.html#adef-readonly
  $form['username'] = array(
    '#type' => 'textfield',
    '#title' => t('username'),
    '#attributes' => array('disabled' => 'disabled'),
  );

http://www.w3.org/TR/html4/interact/forms.html#adef-disabled

- p

I am able to disable the text field.
Thanks for the quick reply. Thanks a lot.

Thanks,
Sagar.

Thank your.

I have been trying

'#readonly' => ture,
'#readonly' => readonly,

Is not correct..

but use '#disabled' => ture, Is feasible

Thank you very much ..
'#attributes' => array('readonly' => 'readonly'),

'#disabled' => TRUE, is work

edian tenan...
it's work, the field became grey, thank's

来自 https://drupal.org/node/74824
普通分类: