In D7 I have a field photo on the user account page (user edit form).

I have a conflict between the modules conditional state and simplecrop therefore I like to disable the conditional state module for this field and replaced it by some code in the form_alter hook..

When another field has a value of ok/not oke I can e.g. use the function like

if( set my check here) {

But I do not want to unset the field. I would like to display the image and put some text here.

How to achieve this?


Using unset() with form elements is always wrong.

To avoid the form element is shown, just set its #access property to FALSE or to the value returned from a function, and that form element will not appear in the form, or it will appear basing on what returned from that function.
Once you make it not accessible from the currently logged-in user, you can add the form elements you need, not forgetting to add the form submission handler to handle the input given from the users for those form elements you add.

| improve this answer | |
  • Thxs that is good to know, i will use that. It is however very unclear for me how to add a form element in the way I need. What I need is displaying a image and some text. How will this form element looks like in code? – Justme Nov 16 '16 at 12:03

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.