-
-
Save evandonovan/401220 to your computer and use it in GitHub Desktop.
Wim Leers' recursive code - find form elements of given type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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