0

I'm trying to modify my exposed filter block to put each of the controls inside fieldsets, and make other modifications to them.

However, when I try to utilize a foreach loop to do this, none of my changes are 'sticking'.

foreach($form_state['input'] as $delta => $input) { 
    $collapsed = (empty($input) ? TRUE : FALSE);

    $form[$delta . '_fieldset'] = array(
        '#type' => 'fieldset',
        '#title' => t($form['#info']['filter-' . $delta]['label']),
        '#collapsible' => TRUE,
        '#collapsed' => $collapsed,
    );

    $form[$delta . '_fieldset'][$delta] = $form[$delta];
    unset($form[$delta]);
    unset($form['#info']['filter-' . $delta]);

}   

This wont work, but this will:

$delta = 'field_resource_type_tid';
$collapsed = (empty($form_state[$input][$delta]) ? TRUE : FALSE);

$form[$delta . '_fieldset'] = array(
    '#type' => 'fieldset',
    '#title' => t($form['#info']['filter-' . $delta]['label']),
    '#collapsible' => TRUE,
    '#collapsed' => $collapsed,
);

$form[$delta . '_fieldset'][$delta] = $form[$delta];
unset($form[$delta]);
unset($form['#info']['filter-' . $delta]);

I've been trying to find out why this wont work, but I can't for the life of my figure out what the form modifications wont stick when done inside this foreach loop.

2 Answers 2

0

I've finally managed to resolve my issue, but I'm not sure why. I decided to change what array I was using to iterate through the filter fields on my form. By switching to iterating through the form array instead of form_state, any changes I make to it now are sticking.

foreach($form['#info'] as $delta => $input) {
    $filtername = $input['value'];
    $collapsed = (empty($form_state['input'][$filtername]) ? TRUE : FALSE);

    $form[$filtername . '_fieldset'] = array(
        '#type' => 'fieldset',
        '#title' => t($form['#info']['filter-' . $filtername]['label']),
        '#collapsible' => TRUE,
        '#collapsed' => $collapsed,
    );

    $form[$filtername . '_fieldset']['' . $filtername] = $form[$filtername];
    unset($form[$filtername]);
    unset($form['#info']['filter-' . $filtername]);

}
-1

Try passing the $vars by reference by prefixing with "&":

foreach(&$form_state['input'] as $delta => $input) 
1
  • I'm sorry, but that just tosses a syntax error. Additionally, if I try to pass the $input as byref it doesn't change the output.
    – EmGee
    Aug 19, 2014 at 17:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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