Hello,

I have to use Drupal 8 core contact form generator to create custom forms other than the default contact forms User contact form and Site-wide contact form as there is no Webform yet available. However, I cannot add captcha to them. They do not show up as options to enable in /admin/config/people/captcha/captcha-points

How can I add protection to my custom core contact forms? Having no protection is not an option.

Thank you in advance.

M

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lilbebel created an issue. See original summary.

pallavi_sugandhi’s picture

Status: Active » Closed (fixed)

You need to add capcha point from "admin/config/people/captcha/captcha-points".
In capcha point setting add form id of your custom form for ex : "contact_message_feedback_form"

lilbebel’s picture

Yes, I know that but my question is how to add to custom core contact forms. It only gives the option to add to the default core contact forms (feedback and personal). I have created my own forms and they don't show up as an option to add captcha too. Only the default system forms are showing as options to add captcha too which leaves all custom forms (not feedback or personal etc...) unprotected.

In the attached image, you can see I added a form called "Practitioner's Application Form". When I go to /admin/config/people/captcha/captcha-points, I only have the options to add captcha to the default system contact forms:

contact_message_feedback_form
contact_message_personal_form

Nowhere is there an option to add it to my custom form/s.

Thanks.

M

lilbebel’s picture

Status: Closed (fixed) » Active
lilbebel’s picture

lilbebel’s picture

Category: Support request » Bug report
pallavi_sugandhi’s picture

Status: Active » Needs review

I have created custom contact form from "Stucture-> contact form-> Add contact form". From here I have created new contact form with name "Careers" and his form id is "contact_message_career_contact_form_form".
After that I added capcha point from "admin/config/people/captcha/captcha-points".
In capcha point setting add form id of your custom form for ex : "contact_message_career_contact_form_form".
Now the captcha is showing properly on this custom contact form.

lilbebel’s picture

Thank you pallavi_sugandhi.

M

lilbebel’s picture

Category: Bug report » Support request
Status: Needs review » Fixed
pallavi_sugandhi’s picture

Status: Fixed » Closed (fixed)
therobyouknow’s picture

I can add some useful information to help others here, if they need it.

The difficulty I overcame was pinpointing exactly what the "Form ID" is of the contact form I created in order to activate a Captcha set up on that form's page.

I should say, as a developer, I fully aware of what the "Form ID" is and have used it in building forms programmatically as well as modifying existing forms in hook_form_alter and using form id to select to correct form to alter.

However, it may not be obviously apparent how to find this out for the form you created.

With captcha enabled on your site, you'd go to admin/config/people/captcha/captcha-points to add an entry for your form and click "Add captcha point"

On doing so, a page with title "Add Captcha Point" is shown, asking for "Form ID".

Screenshot of this page:

set up captcha asking for Form ID

To get this "Form ID", open in another browser window or tab, your site page that has the form showing and then right click somewhere near in and click Inspect (or similar option) to get your browser to open another window with that page's html source.

Then use the browser's search facility in that source view window to search for this actual string, specifically: "form_id". The search will highlight it in the html code, and next to it you'll see that form ID string you need for setting up the captcha.

Here's a screenshot showing the form id found - see the 'value' html attribute nearby the form_id found. Note the value of the 'value' html element attribute, in my case it's: value="contact_message_sitewide_form" - the Form ID is inside these quotes - contact_message_sitewide_form (for my example).

pinpointing the form ID - by searching for its label ("form_id")

Go back to the "Add CAPTCHA point" page and put this form id in the box, then select the captcha challenge type you want from the drop down menu selector. And click save.

If you refresh the page that your form is on, you should now see the Captcha. You might need to clear the cache before refreshing (go to: admin/config/development/performance - and click "Clear all Caches")

Credit for the search "form_id" to poster here:
https://www.drupal.org/forum/support/module-development-and-code-questio...

To illustrate these steps (in addition to the screenshots) here's my situation/example:

I have a general contact form on a page with URL /contact
I think it might have come with my drupal distro (I can't remember if it was there or if I added it)
I followed the steps above to get its ID, and its id is: "contact_message_sitewide_form".
Don't let the "machine name" confuse things, what is needed is the "Form ID" for setting up the captcha.

I should note that you might want to check first on "admin/config/people/captcha/captcha-points" that there isn't already a form ID entry there and that it just needs enabling for your form.

Sometimes these great things don't have detailed joined up steps and they breeze past them, leaving one kinda thinking that they are not in the "inner magic circle" to know. I like to split these things open, get it out there, so everyone knows.

Edited:
Corrected step where it's the 'value' html attribute value that has the form id to use, rather than aforementioned 'name. But a couple of folks still already got what I meant beforehand and found it very useful - you are most welcome! :)

ph7’s picture

@therobyouknow #11 Thank you for this very useful information. I had been banging my head on what actually 'Form ID' meant. I was thinking it was an CSS ID.

therobyouknow’s picture

Ah you're welcome @ph7 :)

jos_s’s picture

@therobyouknow #11 This was exactly what I was looking for. Thanks for explaining!

therobyouknow’s picture

you're most welcome @jos_s !

drupalfan2’s picture

Thank you for #11.

The solution is:

Open your webform in your browser, search for "form_id" in the html source and use the form_id to create a new captcha point.

ryanbuckley@gmail.com’s picture

Wow, what a terrible UX