I have a menu for user to enter user details which should visible only to logged in user, it works fine. Now I want to add another restriction where I want menu to be displayed only to the user who ticked the checkbox during registration (i.e.,) In registration form there will be a checkbox when user tick the checkbox the menu should be visible otherwise menu should not be accessed by use. I tried following code but not working.

 function my_module_form_alter(&$form, &$form_state, $form_id) {
   if($form_id = 'user_register_form'
   $form['checkbox1'] = array (
      '#title' => 'XYZ',
      '#type' => 'checkboxes',
      '#options' => array('Sell themes'),

 function my_module_user_register_form_submit_handler($form, &$form_state) {
   $check = $form_state['complete form']['checkbox1'][0]['#checked'];
 function check() {
   if($check !== 1) {
   return TRUE;
   return FALSE;
 function my_module_menu_alter(&$items){
   $items['node/add/detail']['access callback'] = 'check';
   $items['node/add/detail']['access arguments'] = array(1);

$check return 1 if checkbox is ticked. But it is not working. Please Correct my mistake. Thank You

  • 1
    Your function check(): $check isn't global, so you can't check anything. – Huelfe Sep 24 '15 at 7:53
  • Your not showing your full code. – alyssaeliyah Sep 24 '15 at 7:53
  1. Go to admin/config/people/accounts/fields and add a boolean field.
  2. In your MYMODULE_form_alter() add a '#type' => 'checkbox' form field and a custom submit handler.
  3. Inside that custom submit handler save the checkbox value into the user's boolean field from step 1.
  4. Inside your MYMODULE_menu_alter() call global $user and check that field's value $user->field_sell_themes and build the access control accordingly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy