It would be great if captcha images could always appear above the Send/Submit button! For example on my sitewide contact form the captcha image is below the button and thats really ugly (Look at the screenshot)! I dont think this is a feature request, but a must have for captcha.module.

captcha.png4.38 KBprofix898
Members fund testing for the Drupal project. Drupal Association Learn more


sachinwfs’s picture

so i haven't yet figured out how to move the captcha around the contact form (even if you just use the mathematical captcha it's placement is all screwed), but i have figured out a way to make it look a bit prettier:

in captcha.module:

  if ($flag && isset($trigger)) {
    $form['#submit'] = array('captcha_submit' => array()) + $form['#submit'];
    if (!_captcha_validate($_POST['edit']['captcha_response'])) {

add this line either before or after the other $form definition:
$form['spacer'] = array('#value' => '<br /><br />';

this is definitely a kludge, mainly because i'm not at all familiar with either drupal or php but it seems to work.

as far as moving it to above the submit button, i suspect it has something to do with weights. i'm going to work on it some more (it bothers me too!) and i'll post here if i make any more progress.

sachinwfs’s picture

yikes, typo. try this instead:
$form['spacer'] = array('#value' => '<br /><br />');
(there is now a closing parenthesis before the semi-colon)

profix898’s picture

I use some code like this

$form['myformitem']['text'] = array('#value' => t('Test Test Test'));
array_splice($form, 5, 0, $form_insert);

to control the position the form item is inserted at.
(Adjust the '5' to an appropriate value.)

I think the $captcha_points array could be easily extended to contain
not only the form_name but also a position for inserting captchas.
For example ...

$captcha_points = array(
 array('comment_form' => t('Comment Form'), 'posisiton' => 5),
 array('user_login' => t('Comment Form'), 'posisiton' => 3),

I havent looked at the implementation in captcha.module, but
it shouldnt be hard to modify the source accordingly.

profix898’s picture

Upps. Sorry!
$form['myformitem']['text'] ... must be $form_insert['myformitem']['text'] of course.’s picture

Wouldn't the simplest way be to just adjust the weight?


function captcha_captchachallenge(&$form, &$captcha) {

just change it appropriately in line 144
(talking about cvs-version 2006/11/02)

    '#weight' => 1,

unless you have already redefined weights in the contact form,
this makes the challenge appear below the submit button.

Matt B’s picture

We want the challenge to appear above the send / submit button - not below it. Why does this only affect the contact form and not the user registration form?

Does changing the weight in captcha_captchachallenge affect the use of textimage as well?

Matt B’s picture

Title: position of captch image in forms » position of captcha image in forms

I made this change to textimage.module (to the textimage_captchachallenge function on line 19). This moves the captcha textimage to just above the submit button:

function textimage_captchachallenge(&$form) {

  $insert_form = array ('captcha_response' => array(
    '#type' => 'textfield',
    '#title' => t('Image Validation'),
    '#default_value' => '',
    '#required' => TRUE,
    '#validate' => array('_captcha_validate' => array()),
    '#description' => t('Please type in the letters/numbers that are shown in the image above.'),
    '#prefix' => '<img src="' . url('_textimage/image/'.time()) . '" '.$imageSize[3].'  alt="Image Validation: you will need to recognize the text in this image."/>',

  $position= array_search("submit", array_keys($form));
  $form = array_merge(array_splice($form, 0, $position), $insert_form, $form);

  return $form;

It works on my implementation, on the contact form and the user registration form and I have not needed to test it on other forms. (I've also changed the wording of the alternative text for the image in my version of the function as the original is not user friendly)


wundo’s picture

Status: Active » Closed (fixed)