1

This works great in a module with a single form, however in a module with multiple forms the form does not show up in the permissions list. Is there something that I need to do differently for modules with multiple forms? For example, do I need to add security to each form before it will recognize it for any forms in the module?

I add this to hook menu:

'access callback' => 'user_access',
'access arguments' => array('Spring Grove Scorecard Access'),

Then use this function:

function form_scorecard_permission() {
    return array(
       'Spring Grove Scorecard Access' => array(
       'title' => t('Spring Grove Scorecard Access'),
       'description' => t('Allows users to access the Spring Grove Scorecard.'),
    ),
  );

1 Answer 1

0

This was my fault for not completely understanding how the permissions function worked. I didn't realize only one function is needed to house all form permissions. The following code works great. Hopefully it will help others who aren't all that bright like myself:

function glatfelter_supplier_action_register_menu() {
  $items = array();

  $items['sar_performance_form'] = array( 
    'title' => 'SAR Performance',
    'description' => 'SAR Performance Form',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('sar_performance_form'),
    'access callback' => 'user_access',
    'access arguments' => array('QCA SAR Performance Form Access'),
  );

    $items['sar_sdr_form'] = array( 
    'title' => 'SAR SDR/NCR',
    'description' => 'SAR SDR Form',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('sar_sdr_form'),
    'access callback' => 'user_access',
    'access arguments' => array('QCA SAR SDR Form Access'),
  );

  return $items;
}

//***PEFORMANCE FORM***
function sar_performance_form($form, &$form_state) {

   //Display the overview
   $form['fs_sar_performance_overview'] = array(
     '#type' => 'fieldset',
     '#title' => t('Overview'),
   );

   $form['fs_sar_performance_overview']['sar_performance_overview'] = array(
     '#markup' => t('Performance form overview goes here'),
   );

   //Display the form
   $form['sar_performance_something'] = array(
     '#markup' => 'Form input can start here',
   );

   return $form;
}

//***SDR FORM***
function sar_sdr_form($form, &$form_state) {

   //Display the overview
   $form['fs_sar_sdr_overview'] = array(
     '#type' => 'fieldset',
     '#title' => t('Overview'),
   );

   $form['fs_sar_sdr_overview']['sar_sdr_overview'] = array(
     '#markup' => t('SDR form overview goes here'),
   );

   //Display the form
   $form['sar_sdr_something'] = array(
     '#markup' => 'Form input can start here',
   );

   return $form;
}

//This function adds the forms to the permissions menu
function glatfelter_supplier_action_register_permission() {
    return array(
       'QCA SAR Performance Form Access' => array(
       'title' => t('QCA SAR Performance Form Access'),
       'description' => t('Allows users to access the SAR Performance form.'),
       ),

       'QCA SAR SDR Form Access' => array(
       'title' => t('QCA SAR SDR Form Access'),
       'description' => t('Allows users to access the SAR SDR form.'),
       ),

    );
}

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.