How can I create a hidden character field in D7 for a text field that hides the user input like the password field does? For example a field called "social security number" should not display the users input in plain text, but instead hide the input. Is there a module that can do this? Or how would that be realized?

  • What is the issue to use '#type' => 'password', field?
    – Prem Patel
    Feb 2, 2018 at 11:11

1 Answer 1


You can with '#type' => 'password' in your form.


$form['social_sec'] = array(
  '#type' => 'password',
  '#title' => t('Social Security'),
  '#description' => t('Please enter your social security number'),
  '#size' => 9,
  '#maxlength' => 9,
  '#required' => TRUE,

If you want this as a field in a node's form, then you will have to use hook_form_BASE_FORM_ID_alter and alter an already existing field.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.