Hi,
With reference to the post : http://drupal.org/node/358356
I am having difficulty getting this piece of code to work. I am making a filter based system with select boxes. The first select shows the countries. When a country is selected it will create a new select box below it with all the provinces/states in it. You select a province/state and it will create a new select box that will show all the cities/towns.
Country -> Province/states -> City/Town -> suburbs
I have had a look at #ahah and that gives me what I need to create a new field on an event. The problem I have is that I need to somehow get the value that was selected in the country select box inorder to generate the province box.
Does anyone have an idea on how I can approuch this problem? Maybe some sample code?
Thanks in advance,
Davin
Comments
I have been tackling this...
I have been tackling the ahah form stuff this weekend. I used the pol and upload modules as a guide for how to accomplish what I wanted.
Here is how the poll module does it.
I hope that help explain how to do it a little.
Adam A. Gregory
_____________________________
Drupal Developer and Consultant
https://goo.gl/QSJjb2
Acquia Certified Developer-Back end Specialist
Thanks for the response
Hey,
That works fine for the poll say, but, how do I pass the selected value from the first object(That is firing the event, in this case the Country field), to the next object that is to be created using that value? this being the province select box. See the poll creates a new field that gets a new name and thats about it, it never needs to be generated based on the previous poll. So when it gets submitted it submits all those new values.
I understand what you are explaining and you have it spot on but my problem is not getting solved, no matter which way I work it :(
Thanks for the response :)
Davin
HA! Some success
HA!
I have a partial solution and it works pretty well. :D All I basically did was to go check the $_POST values. This gave me the value I wanted to carry over. Works great!
Now the next part of this problem is to get this part to work "Province -> Town". How do I declare a field to have a #ahah function if it doesn't exist yet? I have tried doing the same as the original but that doesn't seem to be working. I also tried to make a hidden field so it could generate the JSON I think but that isn't working either. Anyone have any ideas for this?
Thanks in advance,
Davin
Here are my thoughts
In general Drupal discourages using $_POST to retrieve the various values of form and while there is nothing technically wrong with it it is better for coding standards to merge the $post results in your #ahah callback into $form_state['values'] using something like $form_state = array('values' => $_POST);
once you set the $form_state you could use a conditional in your form function some thing like this
You can just set the ahah callback and stuff the same for each element and have the callback merge the post values into $form_state then re-render the form with the $form_state set. It should then be able to iterate through a conditional similar to the above.
Adam A. Gregory
_____________________________
Drupal Developer and Consultant
https://goo.gl/QSJjb2
Acquia Certified Developer-Back end Specialist
Not getting it
Hi arcaneadam,
I understand what you are getting at and it makes perfect sense. What I am having trouble getting my mind around is the actual taking of the form from the cache and then adding the new elements. It makes perfect sense. But in code I cannot get it working.
So what I understand is this.
1. The form is generated with only showing the country options.
2. This country field look something like this:
3. This will then just say rebuild the form and then the next field will be rendered based on your code above?
Does this make sense?
Thanks in advance,
Davin