0

I am working on the quiz module.
I have to modify the form node/add/multichoice by hiding some of the form elements in it.
With the help of krumo function of devel module, I am able to find the correct form elements and set ['#access'] to FALSE in order to hide them.
All this is done in a custom module using the hook_form_alter().

But the problem is that I have to hide advanced fieldset under alternatives. The path for form element for advanced fieldset is thus like below :
$form['alternatives'][0]['advanced']
$form['alternatives'][1]['advanced']
But there is an option of add more alternatives.
What is the path for form elements which are ajax enabled.

  • You have to loop through $form['alternatives']: foreach ($form['alternatives'] as $delta => &$alternative) { $alternative['#access'] = FALSE; } – Beebee May 25 '16 at 11:15
  • thankyou so much. Let me try and get back to you.regards. – Tulika Sharma May 25 '16 at 11:16
  • 2
    Probably best to loop through element_children($form['alternatives']), you're likely to run into problems otherwise – Clive May 25 '16 at 11:22
  • it is throwing errors. please look into it. – Tulika Sharma May 25 '16 at 11:39
  • Warning: Illegal string offset '#access' in znew_form_alter() (line 24 of C:\xampp\htdocs\newsite\sites\all\modules\znew\znew.module). Warning: Illegal string offset '#access' in znew_form_alter() (line 24 of C:\xampp\htdocs\newsite\sites\all\modules\znew\znew.module). Warning: Cannot use a scalar value as an array in znew_form_alter() (line 24 of C:\xampp\htdocs\newsite\sites\all\modules\znew\znew.module). – Tulika Sharma May 25 '16 at 11:40
1
foreach (element_children($form['alternatives']) as $delta) {
  $form['alternatives'][$delta]['advanced']['#access'] = FALSE;
}

Something like this.

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.