How can I output a text string when my dynamically built form is empty? I have a form that is dynamically built. It renders a list of check boxes, but sometimes there are none to render - it is empty. In this circumstance, instead of the forms #titles with nothing below them being rendered, I'd like to output t('None'). For the type #tableselect the option seems to exist: #empty, but not for checkboxes or any other type. How can I acheive this? Thanks.

Code added:

    // Form defintion.
    $form['posts'] = array(
        '#type' =&gt; 'checkboxes',
        '#title' =&gt; t('Member responses to:'),
        '#options' =&gt; $options['post'],
    );
    $form['terms'] = array(
        '#type' =&gt; 'checkboxes',
        '#title' =&gt; t('Posts tagged with:'),
        '#options' =&gt; $options['term'],
    );
    $form['groups'] = array(
        '#type' =&gt; 'checkboxes',
        '#title' =&gt; t('Group posts for:'),
        '#options' =&gt; $options['group'],
    );
    $form['submit'] = array(
        '#type' =&gt; 'submit',
        '#value' =&gt; t('Remove'),
    );
    return $form;


I tried at the bottom:

if(empty($options)) {
  return t('None');
} else {
  return $form
}


...but this threw an error.
I don't know what's the code before/after and exact context in which you are using it., but this could work for you:

if(empty($options)) {
  $form['empty']['#markup'] = t('None');
}
else {
  // Form defintion.
  $form['posts'] = array(
      '#type' =&gt; 'checkboxes',
      '#title' =&gt; t('Member responses to:'),
      '#options' =&gt; $options['post'],
  );
  $form['terms'] = array(
      '#type' =&gt; 'checkboxes',
      '#title' =&gt; t('Posts tagged with:'),
      '#options' =&gt; $options['term'],
  );
  $form['groups'] = array(
      '#type' =&gt; 'checkboxes',
      '#title' =&gt; t('Group posts for:'),
      '#options' =&gt; $options['group'],
  );
  $form['submit'] = array(
      '#type' =&gt; 'submit',
      '#value' =&gt; t('Remove'),
  );
}
return $form;