In Progress

Drupal Form AJAX

Hi,

I have created a simple webform which have two select fields. I want that when user select first select option then second select box is updated with values relevant to selected option.

I have created a custom form and tried using form AJAX property. This work fine but the only issue is that when I change any value then it still sends a default value rather than selected value.

I think the problem is with form_state but I could be wrong.

function apply_now_form_webform_client_form_69_alter(&$form, &$form_state) {

$options = _apply_now_get_car_makes_dropdown_options();

$selected = isset($form_state['values']['car_make']) ? $form_state['values']['car_make'] : key($options);

$form['submitted']['car_make']['#options'] = $options;

$form['submitted']['car_make']['#default_value'] = $selected;

$form['#submit'][] = 'your_submit_handler';

$form['submitted']['car_make']['#ajax'] = array(

'callback' => 'apply_now_dependent_dropdown_callback',

'wrapper' => 'dropdown-second-replace',

'method' => 'replace'

);

$form['submitted']['car_model']['#prefix'] = '<div id="dropdown-second-replace">';

$form['submitted']['car_model']['#suffix'] = '</div>';

$form['submitted']['car_model']['#options'] = _apply_now_get_car_model_dropdown_options($selected);

$form['submitted']['car_model']['#default_value'] = isset($form_state['values']['car_make']) ? $form_state['values']['car_make'] : '';

}

In the second last line in code, you will n otice that $selected is passed but this is always the first value in $options rather than what user selected.

Thanks

Skills: Drupal, Electronic Forms, PHP

See more: prefix problem, prefix function, always property, form submit php, array form, form array, select option, drupal submit, php form array, simple form ajax, drupal dropdown form, form dropdown, ajax custom form, ajax select box php, dropdown php using ajax, dropdown using ajax php, submit simple form, drupal webform dropdown, replace values select, drupal custom user, drupal login ajax form, custom webform drupal, change form ajax, drupal php function, php function drupal

About the Employer:
( 210 reviews ) Leeds, United Kingdom

Project ID: #5149898

Awarded to:

ngocleanh

I can fix it. I ready begin now. ======================================================================================================================================================

$34 USD in 0 days
(153 Reviews)
6.8