<p>
<p>
<?
// download this code:
if (arg(2) == 'code'){
  $node=node_load(arg(1));
  header('Content-type: text/php');
  header('Content-Disposition: attachment; filename="code.php"');
  die($node->body);
}
print l('download this code','node/14/code');
?></p>

<p>I was having some issues with conditional fields <a href="http://drupal.org/node/227416">here</a> and <a href="http://drupal.org/node/231384">here</a>.</p>

<p>I thought I would make a little tester to show some ideas I had about fixing the javascript end of things.</p>

<p>A current limitiation of this approach is that it checks this.id in the javascript, so the keys are limited to ID, but eventually I think it'd be cool to support #whatever as well as .whatever in the keys, so that you could match anything, and hide/show multiple things with one declaration!</p>

<p>This would allow weird stuff like hiding all odd rows in a table.('tr:odd')</p>

<script type="text/javascript">
// this should go in a drupal_add_js in a seperate file.  it's here to make it quick
$(function(){
  // for all field ids in Drupal.settings.conditional_fields set
  // the click handler to check the value, and hide/show fields based on it's value
  $.each(Drupal.settings.conditional_fields,function(key,val){
    $('#'+key).click(function(){
      for (i in Drupal.settings.conditional_fields[this.id]){
        for (j in Drupal.settings.conditional_fields[this.id][i]){
          $('#'+i).parent().hide();
          checkval=$(this).val();
          checktype = $(this).attr('type');
          if ((checktype == 'checkbox' || checktype == 'radio')){
            checkval=$(this).attr('checked');
          }
          if (Drupal.settings.conditional_fields[this.id][i][j]==checkval){
            $('#'+i).parent().show();
            break;
          }
        }
      }
    });
    // initial value
    $('#'+key).click();
  });
});
</script>

<?php

function test_form(){
  $form=array();
  $form['#description']=t('This is just a tester form. Switch Log to see it in action.',array('%URL%'=>l('quickstart','http://api.drupal.org/api/file/developer/topics/forms_api.html/5')));

  $form['access'] = array(
    '#type' => 'fieldset',
    '#title' => t('Access log settings'),
    '#tree' => TRUE,
  );

  $form['access']['log'] = array(
    '#type' => 'select',
    '#title' => t('Log'),
    '#description' => t('The log.'),
    '#options' => array('no'=>'no','yes'=>'yes'),
  );
  $form['access']['controller2'] = array(
    '#type' => 'checkbox',
    '#title' => t('Second controller'),
    '#description' => t('This controls other things.  I still don\'t have double-parenting worked out in a really smart way, but it does work'),
    '#options' => array('no'=>'no','yes'=>'yes'),
  );

  $options=drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800), 'format_interval');

  $form['access']['timer'] = array(
    '#type' => 'select',
    '#title' => t('Discard logs older than'),
    '#default_value' => variable_get('timer', 259200),
    '#options' => $options,
    '#description' => t('The timer.'),
  );

  $form['tester'] = array(
    '#type' => 'markup',
    '#value' => "This is some tester text, that depends on log=no. I had to wrap it in 2 div's, so there is a parent, and an element. (the parent is hidden.) Notice that this is not in the same fieldset. As an additional demonstration, I added my search block and logo to be hidden on different conditions, as well.",
    '#prefix'=>'<div><div id="test_text">',
    '#suffix'=>'</div></div>',
  );

  return $form;
}

// this should be generated by $form['#conditional']  stuff, not enough time to work out details...
$conditional_fields=array(
  'edit-access-log'=>array(
    'edit-access-timer'=>array('yes'),
    'test_text'=>array('no'),
    'search'=>array('no'),
  ),
);
// just copy it
$conditional_fields['edit-access-controller2']=array(
  'logo'=>array(0),
  'edit-access-timer'=>array(1),
);

drupal_add_js(array('conditional_fields'=>$conditional_fields), 'setting');
print drupal_get_form('test_form');
?>