Using hook_form_alter I have incorporated certain taxonomy vocabularies into my form. I understand that through $form_state -- a single array is passed by reference along through each stage of form processing.
My question is does the array include the taxonomy $tids selected from the $vids which have been included in the form through hook_form_alter...and if yes how would they be placed in $form_state['storage'] as I would like to use them in the creation of a multi-step form.
I have searched the forum extensively as well as numerous online searches to find the answer...however the only forum topic on issue left me to conclude that this is not a possibility with Drupal at this stage?
Thanks for any clarity on this issue.
Comments
What does your
What does your hook_form_alter() look like?
Good Question
Good Question...I was assuming it was through the hook_form_alter as stated above...but actually all that I am doing is changing the title of the field and from being collapsible by default to non-collapsible.
function mymodule_form_alter(&$form, $form_state, $form_id){
if ($form_id == 'mymodule_node_form'){
$form['taxonomy']['#title'] = t('New Taxonomy Title');
$form['taxonomy']['#collapsible'] = FALSE;
}
So I have to assume that the taxonomy vocabularies are being placed in the form by default since I associated them with the node type.
FYI - I have three vocabularies which are incorporated into the form for this node type.
Your continued input as to the primary issue appreciated - e.g. How to pass taxonomy values through $form_state['storage'] so they can be used to determine how and what is displayed in the second-step of a multi-step form.
P.S. I know this can be accomplished with a standard (non-taxonomy) field as follows:
$form_state['storage']['title'] = $form_state['values']['title'];
if ($form_state['storage']['title'] = 'XXXXXX'){
Do this....
}
but don't know how to do it with taxonomy or if the value is even passed in the same manner in the form.
Thanks again
When your form is going
When your form is going through the submit handler do something like this:
You will then be able to access the taxonomy values during your multi-step form process.
Lead Developer and Founder of StreamRiot.com
How would you access a particular vocabulary?
How would you access a particular vocabulary...Or rephrased, " how would you determine a value of a particular vocabulary if you have more than one? Wouldnt you need to tell the if statement which $vid to use to test for the $tid?
I am at a loss as how to do this but I would assume something like this:
// where $vid = 66
if ($form_state['storage']['taxonomy'][66][$tid] == '500'){
// do this or that
}
Thanks your input is a big step in the right direction...I think my issue is a form and/ syntax issue as well.
Are you trying to perform an
Are you trying to perform an action if the user has selected a taxonomy term?
If so and your vid is 66 and tid is 500 then you could go about it this way. I don't have an IDE in front of me to test this but hopefully you'll get the point.
or loop through the vocab
If you want to be more efficient instead of hard coding the vocabulary id into code, you could form_alter the vocabulary form with a checkbox that saves that vocabulary id as a variable (using variable_set) or you could create your own db table and save the value in there. So instead of manually coding the id of the vocab, you would look up the value of that variable with a variable_get. That would prevent inconsitencies between dev/test/production vocabularies.
Hope this helps.
Lead Developer and Founder of StreamRiot.com
This works - thanks for your direction
I used this code inside hook_form_alter...essentially there are three taxonomy terms within a vocabulary which determine what will be displayed on the second page. Of course one problem solved leads to the next to tackle...seems the light bulb has not completely come on when it comes to dealing with taxonomy within the form settings. This form is a modification of the twostepnode module
http://drupal.org/node/382634#comment-1306916
Setting a $form['taxonomy']['#default_value']
Of course to make the above code work you have to pass the $form_state['values']['taxonomy'] to
$form_state['storage']['taxonomy']
$form_state['storage']['taxonomy'] = $form_state['values']['taxonomy'];However this brings up an additional issue --- i.e., It causes the the taxonomy field containing the vocabulary passed into
form_state['storage']['taxonomy']to be null.I know I can set a default value using
$form['taxonomy'][$vid]['#default_value'] = the stored valuein hook_form_alter...however after searching online and the forums cannot find a solution of how to do this.I have done this with other multi-page forms (none node types by converting the taxonomy) however here I need to use the taxonomy term selected by the user which has been stored in the
$form_state['storage']['taxonomy']Once again any assistance from those drupalers who have any insights would be greatly appreciated.
Thanks
Your code helped me.
I was trying to validate a form with a custom module.
I did not want the users to select parents and be able to select only subcategories so I used the code:
Your code was giving me a "Warning: in_array() [function.in-array]: Wrong datatype for second argument" error so I changed the $tid in the above code.
Thank you for your code and hope it helps others as well.