Skip to content

Instantly share code, notes, and snippets.

@alex-moreno
Created July 3, 2013 16:24
Show Gist options
  • Save alex-moreno/5920064 to your computer and use it in GitHub Desktop.
Save alex-moreno/5920064 to your computer and use it in GitHub Desktop.
I always have the same problem when using select forms, and I always forget the solution. Instead of returning an array, like: return $competitions; you have to return a drupal_map_assoc, like this: return drupal_map_assoc($competitions); Otherwise, when selecting the form in hook_submit you will get a number, instead of a human readable string.
/**
* Competition list
*
*/
function mymodule_competitions_results_list_competitions(){
// Main sql
$sql = "SELECT * FROM `node` WHERE type='webform' LIMIT 0,30 ";
$result = db_query($sql);
// WE STORE THEM (FULL NODE) IN AN ARRAY TO BE RETURNED
while( $row = db_fetch_array( $result ) ) {
$competitions[] = $row['title'];
}
return drupal_map_assoc($competitions);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment