User login

Drupal forms: don't forget your tree

    $form['place_taxonomy']['#tree'] = TRUE;  // this was so important and so easy to overlook

If you're working with or creating complex forms, and can't figure out why your, oh, 'place_taxonomy' form data isn't getting to your place_taxonomy_node_save($node, $terms) function -- for example -- even though your hook_nodeapi implementation is most definitely pointing your 'insert' and 'update' operations (or 'op's, as we at Agaric affectionately call them), you may be able to save yourself the trouble of sticking in a drupal_set_message('<pre>' . print_r($node, TRUE) . '</pre>'); to debug.

Check that you have set your tree to TRUE. Otherwise, only the last value in the chain gets passed-- $form['place_taxonomy'][1][20] becomes merely an absurd $form['20'].

(All the above is purely hypothetical and never happens to Agaric. We're professionals.)

Resolution

    $form['base_of_complex_array']['#tree'] = TRUE;

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Internal paths in single or double quotes, written as "internal:node/99", for example, are replaced with the appropriate absolute URL or path. Paths to files in single or double quotes, written as "files:somefile.ext", for example, are replaced with the appropriate URL that can be used to download the file.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Syntax highlight code surrounded by the {syntaxhighlighter SPEC}...{/syntaxhighlighter} tags, where SPEC is a Syntaxhighlighter options string or "class="OPTIONS" title="the title".
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.