diff --git a/captcha.inc b/captcha.inc index 818dd90..22e939b 100644 --- a/captcha.inc +++ b/captcha.inc @@ -286,6 +286,7 @@ function _captcha_get_captcha_placement($form_id, $form) { variable_set('captcha_placement_map_cache', $placement_map); } + drupal_alter('captcha_placement', $placement, $form_id); return $placement; } diff --git a/captcha_api.txt b/captcha_api.txt index bf6b79c..f23792e 100644 --- a/captcha_api.txt +++ b/captcha_api.txt @@ -176,3 +176,30 @@ function foo_captcha_custom_validation($solution, $response, $element, $form_sta These extra arguments are the $element and $form_state arguments of the validation function of the #captcha element. See captcha_validate() in captcha.module for more info about this. +The Captcha module attempts to place the captcha element in an appropriate spot at the bottom of the targeted +form, but this may require customization with complex forms such as multi-part forms. You can customize +placement using hook_captcha_placement_alter, as shown in the following example: +""" +/** + * Custom placement of CAPTCHA elements within forms. + * + * @param placement an array targeting the place within the form to insert the validation element + * @param form_id the id of the form in which you want to affect placement. + */ +function hook_captcha_placement_alter(&$placement, $form_id) { + if ($form_id == 'appform_form') { + $placement['path'][1] = 'fieldset3'; + $placement['key'] = 'submit'; + $placement['weight'] = NULL; + } +} +""" +CAPTCHA elements are real Drupal form elements, which makes it easy to add a CAPTCHA element using +the Forms API, as discussed at http://drupal.org/node/743056 +Example: +""" +$form['my_captcha_element'] = array( + '#type' => 'captcha', + '#captcha_type' => 'captcha/Math', +); +""" \ No newline at end of file