formapi http://alexmoreno.net/ en Drupal form api select elements returning integers instead of string http://alexmoreno.net/drupal-form-api-select-elements-returning-integers-instead-string/03-07-2013 <article role="article" about="http://alexmoreno.net/drupal-form-api-select-elements-returning-integers-instead-string/03-07-2013" class="node node--type-blog node--promoted node--view-mode-teaser"><header><div class="node__meta"> <span> By <span class="node__author"><span><a title="View user profile." href="http://alexmoreno.net/alejandro-moreno" lang="" about="http://alexmoreno.net/alejandro-moreno" typeof="schema:Person" property="schema:name" datatype="" xml:lang="">alexmoreno</a></span></span>, 3 July, 2013 </span> </div> <div class="node__top-wrapper"> <h2 class="node__title"> <a href="http://alexmoreno.net/drupal-form-api-select-elements-returning-integers-instead-string/03-07-2013" rel="bookmark"> <span>Drupal form api select elements returning integers instead of string</span> </a> </h2> </div> </header><div class="node__content text-content"> <div class="text-content field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>I always have the same problem when using select forms, and I always forget the solution.</p><p>Instead of returning an array, like: return $competitions; you have to return a drupal_map_assoc, like this: return drupal_map_assoc($competitions);</p><p>Otherwise, when selecting the form in hook_submit you will get a number, instead of a human readable string.</p> [gist:5920064]</div> <div class="field field--name-taxonomy-vocabulary-1 field--type-entity-reference field--label-hidden field--tag-ref"> <ul class="links field__items field--tag-ref__items"><li class="field--tag-ref__item"><a href="http://alexmoreno.net/drupal" hreflang="es">drupal</a></li> <li class="field--tag-ref__item"><a href="http://alexmoreno.net/formapi" hreflang="es">formapi</a></li> </ul></div> </div> </article> Wed, 03 Jul 2013 16:23:40 +0000 alexmoreno 100 at http://alexmoreno.net