Add Captcha plugin to a custom form on my Wordpress website

Follow the instructions below in order to add Captcha plugin to your custom PHP or HTML form:

  1. Install the Captcha plugin and activate it.
  2. Open the file with the form (where you want to add the captcha).
  3. Insert the following code to display captcha:

if ( function_exists( 'cptch_display_captcha_custom' ) ) {
echo "<input type='hidden' name='cntctfrm_contact_action' value='true' />";
echo cptch_display_captcha_custom();
}

Use PHP tags if you have HTML form:

<?php if ( function_exists( 'cptchpr_display_captcha_custom' ) ) {
echo "<input type='hidden' name='cntctfrm_contact_action' value='true' />";
echo cptchpr_display_captcha_custom();
} ?>

Add the next code to the entered data validation function:

if ( ( function_exists( 'cptch_check_custom_form' ) && cptch_check_custom_form() !== true ) || ( function_exists( 'cptchpr_check_custom_form' ) && cptchpr_check_custom_form() !== true ) ) echo "Please complete the CAPTCHA.";

or (for HTML)

<?php if ( ( function_exists( 'cptch_check_custom_form' ) && cptch_check_custom_form() !== true ) || ( function_exists( 'cptchpr_check_custom_form' ) && cptchpr_check_custom_form() !== true ) ) echo "Please complete the CAPTCHA." ?>

You could add this code to the variable and display this variable in the required place instead of

echo "Please complete the CAPTCHA"

If there is a variable (responsible for errors output) in the validation function, this notification message can be added to this variable. If the function returns 'true', it means that you have entered captcha properly. In other cases the function will return 'false'.

Have more questions? Submit a request

Comments