We would like to target a webform field "email" so that it only has readonly option when the field uses the logged in users email address.

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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