You need to add a recursive form array walker to your code.

function foo(&$form) {
  // process this level of $form
  foreach(element_children($form) as $key) {
    foo($form[$key]);
  }
}

That's it. I have not provided a form_walker function because generalizing this would be a horribly complicated thing and does not worth it.

CommentFileSizeAuthor
#3 array-getslice.patch.txt1.92 KBegfrith
#2 array-args.patch.txt951 bytesegfrith

Comments

moshe weitzman’s picture

Version: » 6.x-1.x-dev

dealing with form arrays is important ... I haven't tested the patch

egfrith’s picture

Status: Active » Needs review
StatusFileSize
new951 bytes

Hmm.... I've got a hack which at least allows one level of hierarchy -- but it is not general, and probably not elegant enough. Nevertheless, it allows me to alter the taxonomy term. I'm trying to get an image gallery where it is possible to have a link to add an image to this gallery, rather than always having to specify the gallery when going to create image.

The patch is attached -- perhaps it might be a starting point for something better.

egfrith’s picture

StatusFileSize
new1.92 KB

Whoops - I shouldn't have set the status since from http://drupal.org/patch I read "Make sure your code is clean and secure. If your patch is just a quick hack, then don't set your issue to Patch status." Sorry folks!

Anyway, I have now got a patch that I think is general and elegant.

A brief description: _prepopulate_form_walk() has gone and _prepopulate_get_walk() has been modified to walk through each element of $_GET['edit'], checking that there is a matching element of $form at each stage. If the end of the $getslice has been reached, the corresponding default_value of the form element will be set. I realise this doesn't use the drupal element_children() function, but I couldn't see an easy way of doing so, and it's not clear to me that it would add to efficiency or security - but I'm willing to be convinced!

eafarris’s picture

Status: Needs review » Fixed

Oh, hell, yes.

Committed to HEAD. Many thanks!

Anonymous’s picture

Status: Fixed » Closed (fixed)