0

I've a field organization_name which is term reference with unlimited values. Whenever somebody saves the node I want to attach a few more terms in this field.

I've tried doing using hook_presave and also using submit handler of Forms API.

But the problem is that they both expect the term to be filled with plenty other values as below. Where do I get those values? From taxonomy_term_load ?

This is the dsm out of the form_state array in the form submit handler.

enter image description here

1
  • Have you thought about using rules? Commented Oct 28, 2013 at 16:59

1 Answer 1

0

The only place you need to add values in your hook_form_alter() is the $form_state['values'] array. In there you should only see the tid value, not the whole term entity.

Alternatively, you can use the Rules module

4
  • I did not ask this. I'm asking what values do I need to fill in tid array in form_state for example: tid, vid, name etc. Or can I simply attach the term object(converted to array) as is?
    – user5858
    Commented Oct 29, 2013 at 4:09
  • Is your dpm() in your question from $form_state['values']? What I'm saying in my answer is that you should not see all that stuff there, but only the tid.
    – goron
    Commented Oct 30, 2013 at 6:40
  • No but I'm seeing all those stuff for all my term reference fields.
    – user5858
    Commented Oct 30, 2013 at 8:39
  • Again, the only place you need to add to in order to add field values is $form_state['values']. Since none of that other stuff appears in there, you don't need to worry about it. Simply add your tids to the field's value array within $form_state['values'].
    – goron
    Commented Oct 31, 2013 at 18:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.