We would like to add a readonly option to a email webform field when the field uses the email address for the logged-in users.

The webform email field has an option to "Set the default value of this field to the user email, if he/she is logged in." and to toggle a "readonly" option.

How would we go about achieving this?


There's two possible approaches you could take here:

  1. Add a custom hook_form_alter to test in php if the user is logged in, and then set the disabled/locked attribute to the field.

  2. Add javascript that on page load checks to see if the body has the "logged-in" class and if the field is already populated/has a value; then disable/lock it.

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