I use his code to populate a select after giving à zipcode.
$form['responsible']['zipcode'] = array( '#type' => 'textfield', '#title' => t('Zipcode'), '#default_value' => empty($account->Dossier->responsable->adresse->codePostal) ? Null : $account->Dossier->responsable->adresse->codePostal, '#required' => True, '#maxlength' => 5, '#ajax' => array( 'callback' => 'ajax_get_cities_callback', 'wrapper' => 'edit-city', 'method' => 'replace', ), ); $form['responsible']['city'] = array( '#type' => 'select', '#title' => t('City'), '#options' => array(), '#required' => True, );
My callback
function ajax_get_cities_callback($form, $form_state){ $client = new SoapClient('myWebservice',array("trace" => true, "exceptions" => true,)); $requestParams = array( 'parameters' => array ( 'numSite' => 1058, 'typeListes' => array( 'RechercheTypeListe' => array( 'typeListe' => 'LST_VILLE', 'param1' => $form_state['values']['zipcode'] ) ) ) ); $dataresponse->requestParams = $requestParams; $response = ""; try { $response = $client->__Call('GetListes',$requestParams); } catch (Exception $e) { var_dump($e); return False; } $form['responsible']['city']['#options'] = array( 0 => "aaaa", 1 => "test2", 2 => "test3" ); return $form['responsible']['city']; }
When I give a zipcode, a new select is created behind the first one.( picture here: https://www.uploady.com/#!/download/zjKvglzRTSe/ZIMYkjSAAaLrUFUq) I tried to return only $form[‘responsible’][‘city’][‘#options’] but it does not fixe.
Any idea ?
Thank you