Hello,
I have two taxonomy populated select boxes in my profile form created using profile2 module, say primary and secondary values. I need to populate values in the second select box according to the options selected in the the first select box. So I need to add an onchange Ajax function for the first select box. First I tried the normal way, by adding the ajax callback in form attributes but at that time I got 'illegal choice' errors. So I googled for some time time and found that we can add the ajax callback to a form filed just like other attributes in the form_alter. But it was not worked for me in my profile form. Can anybody show me the right way to achieve this? Any help will be much appreciated.
Thanks in advance.
By rajeesh on
Comments
Hi, hook_form_alter() will
Hi,
hook_form_alter() will not work for the altering the profile form.
please try with
Hope this will work for you.
Thanks,
Tushar Shantaram Bodake
Real problem is.....
Thanks for your reply. I think you didn't understand my real problem. I already have the form_alter for profile form and it is working fine. The real problem is I want to know how we can add '#ajax' attribute in the profile form alter and poulate the second select box with the selection of the first select box. I laso need to get rid of 'illegal choice' errors that triggered at the time of form submission. I hope now you can understand my problem.
OK, Can you please share
OK,
Can you please share your code snap ? which will easy to find cause for issue..
thanks.
Tushar Shantaram Bodake
Ok. I will explain my problem
Ok. I will explain my problem in detail. As explained in the first post I have two drop down boxes in user profile form, which was created using profile 2 module. I want to reload the options in the second select box according to fist select box selection. Actually we can achieve this by adding ajax attribute to the first select box and then replace the second select box options. Here is the sample code given in examples module.
Here 'ajax_example_dependent_dropdown' is the form id. In my case form id is 'user_profile_form', but we can't use
since it was already defined in the core user module. In my case machine name of the profile using is 'service_provider_profile'. I think we can't use profile_form_alter since it is not returning $form. So Tushar, first I need to write the similar function for the profile form( like function ajax_example_dependent_dropdown($form, &$form_state) ). I think once we get the function then rest of the things will much easier. Thanks for your patience Thushar.
Rajeesh ,Have you solved
Rajeesh ,Have you solved this? can you please share how you solved ?
I am having similar requirement, for address fields I have the table for all the countries, states.cities and want dependent drop downs for state, and city it is taking a lot of time if use with term reference field
none of the address and location modules serve my purpose
I had same problem.I have
I had same problem.
I have solve with the help of http://drupal.org/node/1117428.
Add two line of code on your hook_form_alter() after that you can access $form element on ajax callback,
If you want to alter profile register form you can use profile2 API hook_form_profile2_edit_PROFILE_TYPE_form_alter(),
Thank you.
printing view with the return of the values
Hi, I created my custom module for 2 dependent dropdown, the result of which should be given to the view so that it will be filtered and view is printed. Is it possible