1

im want to 3 radio buttons and user select a one save it in data base and i use following code but it gives error like this

Notice: Undefined variable: admin in ounces_to_ml_form() (line 44 of C:\xampp\htdocs\drupal7\sites\all\modules\ounces_to_ml\ounces_to_ml.module).

Notice: Undefined variable: admin in ounces_to_ml_form() (line 54 of C:\xampp\htdocs\drupal7\sites\all\modules\ounces_to_ml\ounces_to_ml.module).

Notice: Undefined variable: admin in ounces_to_ml_form() (line 64 of C:\xampp\htdocs\drupal7\sites\all\modules\ounces_to_ml\ounces_to_ml.module).

$active = array(0 => t('Closed'), 1 => t('Active'));


$form['settings']['active'] = array(
    '#type' => 'radio',
    '#title' => t('every time'),
    '#default_value' => isset($node->active) ? $node->active : 1,
    '#options' => $active,
    '#description' => t('Instantly: Emailed every time a donor submits a donation'),
    '#access' => $admin,
  );
//////////////////////
//////radio 02 /////////
$form['settings']['active1'] = array(
    '#type' => 'radio',
    '#title' => t('once a day'),
    '#default_value' => isset($node->active) ? $node->active : 1,
    '#options' => $active,
    '#description' => t(' Email once a day'),
    '#access' => $admin,
  );
//////////////////////
//////radio 03 /////////
$form['settings']['active2'] = array(
    '#type' => 'radio',
    '#title' => t('at given time'),
    '#default_value' => isset($node->active) ? $node->active : 1,
    '#options' => $active,
    '#description' => t('Email a day'),
    '#access' => $admin,
  );
//////////////////////

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('save'),
  );


return $form;

i want to know what is the error and what is mean by '#access' => $admin code line

3

#access property in Form API is to set whether the element should be visible to the user or not. If its value is TRUE, the element will not be displayed (not hidden element - #required will not be enforced). From Form API doc:

Whether the element is accessible or not; when FALSE, the element is not rendered and the user submitted value is not taken into consideration.

$admin should be a variable you have forgotten to add/take from where you took the code.

Here is my suggestion to populate $admin variable. At top of the form function, populate $admin:

$admin = user_access('administer site configuration');

user_access function returns (bool) TRUE of the user has the given permission (or FALSE if the current user doesn't). administer site configuration is a general permission that will be usually given to administrators. You can use whatever permission as appropriate for this.

| improve this answer | |

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.