Is there any to set restrict access over custom form (hook_form) fields based on user roles. (i.e) Field Permission Module gives that flexibility to cck but not for custom form fields.
Well i dont know of any module for this but you can do this.
function custom_form(){
//obtained logged in user and his roles
global $user;
$current_role = $user->roles;
//this form field is static
$form = array();
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('name'),
);
//the below form fields are based on the current_role of the user
if(in_array('test1', $current_role)){
$form['conditional'] = array(
'#type' => 'textfield',
'#title' => t('test1'),
);
}
if(in_array('test2', $current_role)){
$form['conditional'] = array(
'#type' => 'textfield',
'#title' => t('test2'),
);
}
return $form;
}
I dont know if this is the exact functionality you need or not. Here it will display textfield 'test1' if user has role test1 and test2 if user has role test2.
Hope this helps.