By brevity on
How can I set a default taxonomy term in the add node form of mycontenttype?
In the themes/garland/template.php function phptemplate_mycontenttype_node_form($form) I tried eg:
$form['taxonomy']['6']['#default_value'] = 17; // not working
But term 17 of vocabulary 6 won't get pre-selected. Do I need to set the tid wihin an array maybe?
I'm glad I found out how to have the category fieldset collapsed by default and the file attachments fieldset open:
$form['taxonomy']['#collapsed'] = true;
$form['attachments']['#collapsed'] = false;
Cheers!
Comments
are you sure that's the
are you sure that's the right array: $form['taxonomy']['6']['#default_value'] and that 17 is a valid term? Is the garland theme enabled and selected?
You may consider using the form_alter hook instead.
Lead Developer and Founder of StreamRiot.com
where in the array
Thanks for your replies, the taxonomy_defaults module sets defaults by
Can I do this in template.php as well? Which part of the array do I need to set, and how?
Do I need to set the #options array maybe, or something like value=selected?
My $form array looks as follows:
$form['taxonomy'][6]['#defaul
$form['taxonomy'][6]['#default_value'] = array(tid => tid); where tid is the term id.
You probably wouldn't want to do that in template.php because that's for theme functions, unless there is a particular theme function for the page you're looking at. Try the fix above first...that should hopefully work.
Lead Developer and Founder of StreamRiot.com
Great
Okay, now I think I have it... http://api.drupal.org/api/function/form_select_options/5 does not have #default_value
Here's what I added to template.php -- where would such stuff sit better? I often do not know where to start hacking...
Cheers!
I dont get these results...
I am assumeing you are using a single select like me, but your code does not produce the same results, though its got to be close! Its just $value is said to be an array in print_r! I also have #default_value in my print_r, but it does not set the value either.
is #value the taxonomy id or the default selection?
EDIT #value is the term_ID and I got it to work so thanks
What about this
What about this module?
http://drupal.org/project/taxonomy_defaults
Re: Taxonomy Defaults
That's just what I need!
Thanks.
Thanks:)
Thanks:)
_
Great module.
However, installing this module showed me how to change it manually. Make a custom module and add this:
The important part is "array(0 => 1)". "custom" is the module name and xxx_node_form is the form ID.
Hope this helps.
Cheers,
Danny