I am creating a custom form and storing data in custom table. I was wondering if there is any method to apply field level permission like

$form['value']['#permission'] = array('access this field');

I know I am having field permission module to apply permission on core fields but how I can achieve this?


As said by Adi, '#access' in your form will give access to a form field based on a user role.

Check this link


I am already not try this but i think it will work

function mymodule_form_alter(&$form, &$form_state, $form_id) {

  global $user;
  if ($form_id == 'FORM_ID') {
  if (in_array('yourrole', $user->roles)) {
  $form['your_field']['#access'] = FALSE;
  • Thanks Adi, I know its possible with php logic, I was looking for something else. I want to control this forms visiblity from drupal admin end so if my client wants to change his mind and ask me to grant access to another role then I won't have to dig the code. – Shabir A. Dec 18 '15 at 12:43
  • then you create a page and provide it handler into config ,in the page you can define role of your site where user can select role or field name to set permission on it – Adi Dec 18 '15 at 13:23
  • handler into config? How? Can you provide a link? – Shabir A. Dec 18 '15 at 13:30

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.