Fieldsets 'IF ELSE' based on checkboxes? So i have a custom form with 3 fieldsets built from FORM API. each fieldset holds its own "mini" form for users to fill out. what i want is the second 2 fieldsets should not display unless either checkbox 2(fieldset B) is clicked or checkbox 3(fieldset C) is clicked. but fieldset one holds the checkbox field and i have it set up as a #tree

$form['Contract'] = array(
 '#theme' =&gt; 'form_panel_table',
 '#tree' =&gt; TRUE,
 '#title' =&gt; t('General Information'),
 '#collapsible' =&gt; TRUE, // Added
 '#collapsed' =&gt; FALSE,  // Added
);
$form['Contract']['first'] = array(
 '#type' =&gt; 'checkboxes',
 '#title' =&gt; t('Products applying for:'),
 '#options' =&gt; array("Product B", "Product C"),
 '#required' =&gt; TRUE, // Added
 );


//if statement should hide this part of form unless checkbox above is clicked
    /* second fieldset starts here for product B */

    $form['Contract']['product B'] = array(
     '#theme' =&gt; 'form_panel_table',
     '#type' =&gt; 'fieldset',
     '#tree' =&gt; TRUE,
     '#title' =&gt; t('product b'),
     '#collapsible' =&gt; TRUE,
     '#collapsed' =&gt; TRUE
    );
    $form['Contract']['product B']['first'] = array(
     '#type' =&gt; 'textfield',
     '#title' =&gt; t('Zip/Postal Code'),
     '#size' =&gt; 30,
     '#maxlength' =&gt; 6,
    );


//one more else if statement for last fieldset should be here?
    /* End of product B. Begin product C */

$form['Contract']['product C'] = array(
 '#type' =&gt; 'fieldset',
 '#tree' =&gt; TRUE,
 '#theme' =&gt; 'form_panel_table',
 '#title' =&gt; t('example'),
 '#collapsible' =&gt; TRUE,
 '#collapsed' =&gt; TRUE
);
$form['Contract']['product C']['first'] = array(
 '#title' =&gt; t('example'),
 '#rows' =&gt; 39,


using php how would i write the if else statement in my custom form(tried it my way didnt show up on my site) in a druapl way?
Assuming you are looking for a #states based solution, which is new in Drupal 7.

First, note that you cannot use 0 as a key for #options. So rewrite your first field set as follows:

$form['Contract']['first'] = array(
 '#type' =&gt; 'checkboxes',
 '#title' =&gt; t('Products applying for:'),
 '#options' =&gt; array('b' =&gt; 'Product B', 'c' =&gt; 'Product C'),
 '#required' =&gt; TRUE, // Added
 );


Now, we hide/show the other fieldsets depending on the above checkboxes' values. 

$form['Contract']['product B'] = array(
  '#theme' =&gt; 'form_panel_table',
  '#type' =&gt; 'fieldset',
  '#tree' =&gt; TRUE, // not necessary if parent element has #tree = TRUE.
  '#title' =&gt; t('product b'),
  '#collapsible' =&gt; TRUE,
  '#collapsed' =&gt; TRUE
  '#states' =&gt; array(
      'visible' =&gt; array(
        ':input[name="first[b]"]' =&gt; array('checked' =&gt; TRUE),
      ),
    ),
);


Likewise, 

$form['Contract']['product C'] = array(
  '#type' =&gt; 'fieldset',
  '#tree' =&gt; TRUE,
  '#theme' =&gt; 'form_panel_table',
  '#title' =&gt; t('example'),
  '#collapsible' =&gt; TRUE,
  '#collapsed' =&gt; TRUE,
  '#states' =&gt; array(
    'visible' =&gt; array(
      ':input[name="first[c]"]' =&gt; array('checked' =&gt; TRUE),
    ),
  ),
);


What we are doing exactly is that we ask the Form API to generate necessary jQuery code that it should only show the field set in question only if the input tag (it's a specially jQuery selector that selects input, textarea, select, etc tags at once) with name "first" and its value c/b is checked. These 2 visibility settings are individual so there is no else if concept here. 

Also note that #tree has nothing to do with the form's settings. if the code above didn't work, try setting if off. When you have #tree, name attribute of input fields get changed so PHP can build an array of submitted information. There is nothing to do with the visibility settings (except it can make our visibility rule never become true)