Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 3 down vote accepted

#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.

share|improve this answer
    
thanks this is what i want to know.. –  wordpresrox Feb 27 '13 at 3:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.