You are here

function _captcha_search_buttons in CAPTCHA 7

Same name and namespace in other branches
  1. 8 captcha.inc \_captcha_search_buttons()
  2. 6.2 captcha.inc \_captcha_search_buttons()

Helper function for searching the buttons in a form.

Parameters

array $form: the form to search button elements in

Return value

array an array of paths to the buttons. A path is an array of keys leading to the button, the last item in the path is the weight of the button element (or NULL if undefined).

1 call to _captcha_search_buttons()
_captcha_get_captcha_placement in ./captcha.inc
Helper function to get placement information for a given form_id.

File

./captcha.inc, line 400
General CAPTCHA functionality and helper functions.

Code

function _captcha_search_buttons($form) {
  $buttons = array();
  foreach (element_children($form) as $key) {

    // Look for submit or button type elements.
    if (isset($form[$key]['#type']) && ($form[$key]['#type'] == 'submit' || $form[$key]['#type'] == 'button')) {
      $weight = isset($form[$key]['#weight']) ? $form[$key]['#weight'] : NULL;
      $buttons[] = array(
        'path' => array(),
        'key' => $key,
        'weight' => $weight,
      );
    }

    // Process children recurively.
    $children_buttons = _captcha_search_buttons($form[$key]);
    foreach ($children_buttons as $b) {
      $b['path'] = array_merge(array(
        $key,
      ), $b['path']);
      $buttons[] = $b;
    }
  }
  return $buttons;
}