How to implement captcha in a simple custom form?

Events happening in the community are now at Drupal community events on www.drupal.org.
djuro-gdo's picture

Hello,

I use Drupal 6.10 and Xampp on windows sp3 for local testing purposes. Started with Drupal a few months ago.
I have seen Rob's video tutorial (btw. it is great) and did so in order to protect my custom html/php mailing form but it does not work. Drupal comment form and others work fine, no matter whether I put image, math or text. Only when I want to use it on my form: nothing happens.

I googled a lot without success, to find some code example because I'm not sure if drupal captcha is supposed to work on custom forms at all?

Could you show me in code how to implement it in a simple form like this:

<form name="myform" action="/thesamepage" method="post">

<input type="text" name="one">
<br />
<input type="submit" value="OK">

</form>

<?php

$word
= $_POST['one'];

print
$word;

?>

Thank you

Comments

captcha on custom form

svenr's picture

I too am looking for an answer to this same question. Did you ever figure this out?

Form API

robloach's picture

The CAPTCHA API is made to work with the Form API. If you're using something else, it will probably not work. You might want to look into another solution, like using reCAPTCHA directly, or Mollom.

I've implemented a Custom

a5342346's picture

I've implemented a Custom login form, following instructions/example at

"Theming the Drupal 6 User Login Form"
http://blog.aphexcreations.net/2009/04/theming-drupal-user-login-form.html

and then added a Captcha to it (http://drupal.org/node/743056).

The Captcha displays fine, but isn't integrated into the Login process. I.e., I can authenticate without filling out the Captcha.

Iiuc, doing the LoginForm this way, I am using the core FormAPI.

How would I get that displayed-Captcha to actually be part of the Login authentication flow, rather than just display? Or, to your comment, have I ventured too far outside the FormAPI?

Ben

I have implemented the

navaneeth_r's picture

I have implemented the Captcha with validation in custom Login form ( http://drupal.org/node/350634). In hook_form_alter I added the following code

  if($form_id == 'user_login'){
    $form['my_captcha_element'] = array(
       '#type' => 'captcha',
       '#captcha_type' => 'captcha/Math',
    );
  }

Captcha validation is working fine. I will comeup with the solution to fully customized login form.

Thanks
R.Navaneethakrishnan
http://navaneethakrishnan-drupal.blogspot.com/

I am creating my own custom

navaneeth_r's picture

I am creating my own custom login form with Captcha. All the login validation and captcha are working fine.

function custom_login_form(&$form_state) {
  global $user;
   if ($user->uid) {
    drupal_goto('user/'. $user->uid);
  }
  $form['name'] = array('#type' => 'textfield',
    '#title' => t('Username'),
    '#size' => 60,
    '#maxlength' => USERNAME_MAX_LENGTH,
    '#required' => TRUE,
  );
  $form['pass'] = array('#type' => 'password',
    '#title' => t('Password'),
    '#description' => t('Enter the password that accompanies your username.'),
    '#required' => TRUE,
  );
  $form['my_captcha_element'] = array(
    '#type' => 'captcha',
    '#captcha_type' => 'captcha/Math',
  );
  $form['#validate'] = user_login_default_validators();
  $form['submit'] = array('#type' => 'submit', '#value' => t('Log in'), '#weight' => 2);
  return $form;
}

I dont know this code is useful to this issue. Sorry if no.

Hi nav18scse

alexpz's picture

Thanks for this one its working very fine in my custom module. It helps me a lot. Again thanks :)

CAPTCHA

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: