Hi All,

I am working for a custom Drupal module with a form.
I placed CAPTCHA for that form.
CAPTCHA is working fine with validation. But it is showing after the submit button.
I need the CAPTCHA before Submit button.
Is there any way to solve this issue?

Thanks
Monalisa

Comments

soxofaan’s picture

FYI: you'll find the CAPTCHA placement logic in captcha.inc (_captcha_get_captcha_placement, _captcha_search_buttons):

/**
 * Helper function to get placement information for a given form_id.
 * @param $form_id the form_id to get the placement information for.
 * @param $form if a form corresponding to the given form_id, if there
 *   is no placement info for the given form_id, this form is examined to
 *   guess the placement.
 * @return placement info array (@see _captcha_insert_captcha_element() for more
 *   info about the fields 'path', 'key' and 'weight'.
 */
function _captcha_get_captcha_placement($form_id, $form) {
// ..
    $buttons = _captcha_search_buttons($form);
    if (count($buttons)) {
      // Pick first button.
      $placement = $buttons[0];
    }
//...

/**
 * Helper function for searching the buttons in a form.
 *
 * @param $form the form to search button elements in
 * @return 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).
 */
function _captcha_search_buttons($form) { ... }

/**
 * Helper function to insert a CAPTCHA element in a form before a given form element.
 * @param $form the form to add the CAPTCHA element to.
 * @param $placement information where the CAPTCHA element should be inserted.
 *   $placement should be an associative array with fields:
 *     - 'path': path (array of path items) of the container in the form where the
 *       CAPTCHA element should be inserted.
 *     - 'key': the key of the element before which the CAPTCHA element
 *       should be inserted. If the field 'key' is undefined or NULL, the CAPTCHA will
 *       just be appended to the container.
 *     - 'weight': if 'key' is not NULL: should be the weight of the element defined by 'key'.
 *       If 'key' is NULL and weight is not NULL: set the weight property of the CAPTCHA element
 *       to this value.
 * @param $captcha_element the CAPTCHA element to insert.
 */
function _captcha_insert_captcha_element(&$form, $placement, $captcha_element) { ... }

As you can see, the CAPTCHA module looks for submit buttons in a form and tries to place it before the first button.

What is the "key" of the submit button in your $form array?

monalisab’s picture

Status: Active » Fixed

Thanks for your reply.
My issue has been solved.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.