1

Is it possible to use the CAPTCHA module on a custom HTML form created in a content page of a Drupal 7 site? I am not using the Drupal Form API or webform modules. The form has the following code:

<form id="signup_form" action="[form action]" method="post" enctype="application/x-www-form-urlencoded">
<div>
<input id="firstName" tabindex="1" type="text" name="firstName" placeholder="First Name" value="" required />
<label for="firstName">First Name* </label>
</div>

<div>
<input id="lastName" tabindex="2" type="text" name="lastName" placeholder="Last Name" value="" required />
<label for="lastName">Last Name* </label> 
</div>

<div> 
<input id="email" tabindex="3" type="text" name="email" placeholder="Email" />
<label for="email">Email* </label>
</div>

<input type="hidden" name="form_id" value="signup_form" />
<div>
<input id="btn-submit" tabindex="6" class="submit" type="submit" name="submitButton" value="SIGN UP" />
</div>
</form>

I'm trying to have reCAPTCHA displayed at the bottom of the page when there has been an X number of form submissions from the same IP address in a given amount of time.   I was hoping CAPTCHA After could work for my custom form -- I tested it on our site's Admin Login page (/user) and it worked great, of course.

I can't seem to get any CAPTCHA displaying on my custom HTML form page. In the General Settings, I selected "Add CAPTCHA administration links to forms" and a drop-down with "CAPTCHA: CHALLENGE "RECAPTCHA" ENABLED" displayed in the content page where the form is coded.

Since the HTML id has nothing to do with $form_id... I referenced this Drupal Stack Exchange page, and haven't been able to generate the form ID...I'm wondering maybe my custom HTML form doesn't have a $form_id because it doesn't use any drupal form modules? If that's the case, then I probably can't use the CAPTCHA module. Could someone please confirm?

Perhaps I can't use any Drupal modules and may need to:

  1. grab the user's IP address from the header via PHP:

    $ip_address = $_SERVER["REMOTE_ADDR"];

  2. store this IP address in some sort of database and add a timestamp

  3. delete any IP address entities in that are over an hour old
  4. count the number of data store entities via loop and if the same IP address appears a certain # of times in a given amount of time, then display reCAPTCHA

Any guidance would be great. Thank you!

2
  • Have you entered your form_id in captcha configuration?
    – Ram
    Commented Feb 19, 2015 at 5:02
  • Yes, in Configuration > CAPTCHA > FORM_ID section, I added "signup_form" and selected a challenge type in the drop-down, but it still did not appear. But signup_form is my HTML form id, and not the $form_id
    – ForTheWin
    Commented Feb 19, 2015 at 14:42

2 Answers 2

2

I'm wondering maybe my custom HTML form doesn't have a $form_id because it doesn't use any drupal form modules? If that's the case, then I probably can't use the CAPTCHA module. Could someone please confirm?

Correct - the Captcha module has been written exclusively for integration with forms built by the core form API. Without a lot of changes, it's not possible to use any of its functionality on a form that hasn't been built by Drupal.

0

Your form id is signup_form have you tried putting that in the captcha configuration so that it knows to add the captcha your custom form.

1
  • Hi @th0ward, thank you for responding. Yes, in Configuration > CAPTCHA > FORM_ID section, I added "signup_form" and selected a challenge type in the drop-down, but it still did not appear. But signup_form is my HTML form id, and not the $form_id :-(
    – ForTheWin
    Commented Feb 19, 2015 at 14:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.