All pastes #456208 Raw Edit

Stuff

public text v1 · immutable
#456208 ·published 2007-04-24 18:34 UTC
rendered paste body
<div align="right">
<?php

  print drupal_get_form('state_dropdown_list',arg(1));

function state_dropdown_list($default_state = NULL){
$options[''] = 'Select A State';
if (arg(1)) {
    //if we have an argument make it the default
    //and place "Show all" in the drop down
   $default_value = "/hotsprings/" . $default_state;
   $options['/hotsprings/'] = 'Show All';
}


     //name the form
  $formname="state_dropdown_list";
     //define our SQL statement
  $sql = "SELECT province as state, count(province) as count FROM location GROUP BY province";
     //Execute the query and grab the results 

  $states = db_query(db_rewrite_sql($sql)); 

while ($state = db_fetch_object($states)) {
   $options["/hotsprings/$state->state"] = "$state->state ($state->count)";
}

//build the form
$form['category'] = array(
  '#type' => 'select',
  '#name' => $formname,
  '#id' => $formname,
  '#title' => '',
  '#default_value' => $default_value,
  '#options' => $options,
  '#description' => '',
  '#multiple' => $multiple = FALSE,
  '#required' => $required = FALSE,
  '#attributes' => array('onChange' => "top.location.href=document.getElementById('$formname').options[document.getElementById('$formname').selectedIndex].value"),
);

  return $form;
}

?>
</div>