Integration with Contact Form 7
-
Hi,
First, let me appreciate that this plugin looks great, modern and sleek.
Its not described but anyway wanted to check if Visual Captcha can be integrated with Contact Form 7 ?
Thanks, keeping my fingers crossed ??
-
Hi, naveenindia.
First of all, sorry about the late reply, but I was not notified about this question.
As for integrating with Contact Form 7, it is possible.
First, you need to know the 2 hooks that contact form 7 triggers to show the form, and to validate/submit the form.
After that, you should add custom hooks in visualCaptcha settings, with the same names as those that your contact form 7 triggers.
Let me know if you need any further help.
Hi BrunoBernardino,
Can please let us know what will be that two hooks, i have tried but its not working properly.
Also can you please let me know that how can i implement it with the Gravity Form plugin.
Its urgent for me so waiting for your quick and positive response.
Thanks,
ManishHi, Manish.
Regarding Gravity Form:
Seems the hooks you’re looking for are “gform_field_validation” ( https://www.gravityhelp.com/documentation/page/Gform_field_validation ) and “gform_pre_submission” ( https://www.gravityhelp.com/documentation/page/Gform_pre_submission ).
Regarding Contact Form 7:
Seems there is no documentation around the hooks and the only thing I found so far was “wpcf7_before_send_mail” in https://xaviesteve.com/3298/wordpress-contact-form-7-hook-unofficial-developer-documentation-and-examples/
I’ll install the plugin and look around the code today.
I’ll tell you something by the end of the day.
Regarding Contact Form 7, it’s possible to have it working, but you’ll have to get your hands dirty in the code because they don’t have action hooks in the right places (the filter one is not standard but easy to apply a fix for).
On
wp-content/plugins/contact-form-7/includes/classes.php
, to show the captcha, you can simply add the following code:ob_start(); do_action( 'wpcf7_custom_visualcaptcha' ); $html .= ob_get_clean();
Right on the line after or before
$html .= $this->form_elements();
(it will show the captcha in an awkward place, before the form or after the send button, but to fix that, you’d have to create a deep integration with shortcode for cf7 — not impossible, just needs coding).That will show visualCaptcha, but not use it for validation.
To validate it, you need to add the following code to
wp-content/plugins/visualcaptcha/visualcaptcha.php
:// Special condition for Contact Form 7 if ( strpos( current_filter(), 'wpcf7_' ) !== false ) { if ( !empty( $arg1 ) ) { if ( is_array( $arg1 ) && isset( $arg1[ 'valid' ] ) && !empty( $arg1[ 'valid' ] ) ) { $arg1[ 'valid' ] = false; $arg1[ 'reason' ] = 'You failed the human verification test. Please go back and try again.'; return $arg1; } } }
Right after
// Special condition for comments if ( strpos( current_filter(), 'comment' ) !== false ) { if ( !empty( $arg1 ) ) { if ( is_array( $arg1 ) && isset( $arg1[ 'comment_post_ID' ] ) && !empty( $arg1[ 'comment_post_ID' ] ) ) { wp_die( __( 'ERROR: You failed the human verification test. Please go back and try again.', 'visualcaptcha' ) ); } } }
Then, for visualCaptcha admin, add a Hook, with the following settings:
Option Name: Contact Form 7
Display Hook: wpcf7_custom_captcha
Validation Hook: wpcf7_validateAlso note that should either plugin be updated, these code changes will be lost.
If enough requests come into github, we will look into making this integration easier.
It is possible and demonstrated here.
Hope that helps.
Regarding Gravity Form, it seems it’s a paid plugin, so I couldn’t test it, anyway, the example above should be enough to help, in case their hooks don’t support the standards we’re looking for (used in default wordpress comments, login, register forms).
Hi
Thanks for your help. I will try this code with contact form.
But for now Gravity Form is priority for me so please if any body can help me to integrate the visual captcha with the Gravity Form.
Thanks
Hi BrunoBernardino.
First of all want to thank you for the great plugin, it’s the best captcha i’ve ever seen.
Tried your way of integration with ContactForm 7, but captcha is not displayed in the form. Please help, maybe any ideas how to find the reason.
Thank you.
Hi
I have tried above code, but its not working.
Main thing is On wp-content/plugins/contact-form-7/includes/classes.php, we dont have this name file only in includes folder.
I have latest version of contact form 7 plugin.
Can you please check and help me out for this issue?
Can we use function.php and add code there and do this, because if we changes in code than we need to hide update so.
Thank you.
Hi, guys.
I’m really sorry, I have no idea why WordPress is not notifying me of posts here. We’ve been helping people integrate visualCaptcha with other languages and custom WordPress plugins through our own support.
Can you guys please say something there, as we’ll need error logs and more information to help you out?
- The topic ‘Integration with Contact Form 7’ is closed to new replies.