Find Jobs
Hire Freelancers

Drupal Form AJAX

$30-250 USD

Completed
Posted over 10 years ago

$30-250 USD

Paid on delivery
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
Project ID: 5149898

About the project

1 proposal
Remote project
Active 10 yrs ago

Looking to make some money?

Benefits of bidding on Freelancer

Set your budget and timeframe
Get paid for your work
Outline your proposal
It's free to sign up and bid on jobs
Awarded to:
User Avatar
I can fix it. I ready begin now. ======================================================================================================================================================
$34 USD in 0 day
4.8 (153 reviews)
6.8
6.8

About the client

Flag of UNITED KINGDOM
Leeds, United Kingdom
4.9
210
Payment method verified
Member since Aug 19, 2009

Client Verification

Thanks! We’ve emailed you a link to claim your free credit.
Something went wrong while sending your email. Please try again.
Registered Users Total Jobs Posted
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Loading preview
Permission granted for Geolocation.
Your login session has expired and you have been logged out. Please log in again.