Does not deal with form arrays

chx - March 23, 2006 - 00:21
Project:Prepopulate
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:critical
Assigned:Unassigned
Status:closed
Description

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

<?php
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.

#1

moshe weitzman - April 12, 2006 - 15:47
Version:<none>» 6.x-1.x-dev

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

#2

egfrith - August 22, 2006 - 22:46
Status:active» needs review

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.

AttachmentSize
array-args.patch.txt 951 bytes

#3

egfrith - August 28, 2006 - 20:58

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!

AttachmentSize
array-getslice.patch.txt 1.92 KB

#4

eafarris - August 28, 2006 - 22:45
Status:needs review» fixed

Oh, hell, yes.

Committed to HEAD. Many thanks!

#5

Anonymous - September 11, 2006 - 22:45
Status:fixed» closed
 
 

Drupal is a registered trademark of Dries Buytaert.