3

I would like to set a read only field in Drupal CiviCRM:

mymodule_civicrm_buildForm($formName, &$form) {
  ...

  // Set default value
  $defaults['readonly_field'] = xxx;
  $form->setDefaults($defaults);

  // Set read only
  $element = $form->getElement('event_type_id');
  $element->updateAttributes(array('disabled'=>true));
}

The field is disabled for input; however, the default value cannot be passed through the form submission.

The form warns that this required field does not input.

Could you advise how to set the read only field correctly?

Thanks a lot!!

1 Answer 1

2

Try $element->updateAttributes(array('readonly'=>true));

The difference between readonly and disabled is a common thing with HTML and forms.

See for example https://stackoverflow.com/questions/7730695/whats-the-difference-between-disabled-disabled-and-readonly-readonly-for-ht

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.