Skip to content

Instantly share code, notes, and snippets.

@evandonovan
Forked from wimleers/find_element()
Created May 14, 2010 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evandonovan/401220 to your computer and use it in GitHub Desktop.
Save evandonovan/401220 to your computer and use it in GitHub Desktop.
Wim Leers' recursive code - find form elements of given type
<?php
function find_element($form, $element_type) {
if (isset($form['#type']) && $form['#type'] == $element_type) {
return $form;
}
else {
foreach (element_children($form) as $name) {
if (is_array($form[$name])) {
$element = find_element($form[$name], $element_type);
if ($element !== FALSE) {
return $element;
}
}
}
return FALSE;
}
}
// Call like this:
$element = find_element($form, 'imagefield');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment