• Resolved roryrory

    (@roryrory)


    Hello
    Thanks for that great plugin that i use in many websites.
    I would like to integrate the captcha of this plugin into my custom form.
    Here is how i create a new form in my plugin using shortcode. The process and validation is done by js/ajax.
    How can i add the do do_action( ‘anr_captcha_form_field’ ); or [anr_captcha] in that form?
    thanks

    add_shortcode( ‘rorycontact’, ‘rorycontact_function’);
    public function rorycontact_function() {
    $formrory=”<form class=’formrorycontact’ id=’formrorycontact’>”;
    $formrory.=”<label for=’roryname’>Your name </label>”;
    $formrory.= ‘<input type=”text” class=”roryparam” value=”” />’;
    $formrory.= “<input type=’submit’ id=’submit’ value=’Submit’>”;
    $formrory.=”<form>”;
    return $formrory;
    }

Viewing 5 replies - 1 through 5 (of 5 total)
  • You can add $formrory.= anr_captcha_form_field(); just before submit button. When sending data in ajax, make sure to pass captcha response to your server. Then in server verify captcha using anr_verify_captcha() function.

    Please also see https://www.shamimsplugins.com/docs/advanced-nocaptcha-recaptcha/getting-started-advanced-nocaptcha-recaptcha/implement-in-custom-form/

    Thread Starter roryrory

    (@roryrory)

    hello
    thanks
    I add the line. SO the form is like this now
    add_shortcode( ‘rorycontact’, ‘rorycontact_function’);
    public function rorycontact_function() {
    $formrory=”<form class=’formrorycontact’ id=’formrorycontact’>”;
    $formrory.=”<label for=’roryname’>Your name </label>”;
    $formrory.= ‘<input type=”text” class=”roryparam” value=”” />’;
    $formrory.= anr_captcha_form_field();
    $formrory.= “<input type=’submit’ id=’submit’ value=’Submit’>”;
    $formrory.=”</form>”;
    return $formrory;
    }

    but nothing appears.

    I checked in the source of the page and i see no extra code or js..
    can you help me?
    What can i check to try to debug?
    thanks

    Thread Starter roryrory

    (@roryrory)

    sorry it is working.
    I have checked the case “Hide Captcha for logged in users?” in admin…and i was login…

    Thread Starter roryrory

    (@roryrory)

    Hello
    Can you confirm me that it is true.
    I get the response in .js and send it to ajax callback function using
    jQuery.ajax({
    url :ajaxurl,
    data: {
    ‘action’:’rorycontactajax’,
    ‘captcha’:$.trim($(‘.g-recaptcha-response’).val())
    }

    then i verify in rorycontactajax using
    if ( anr_verify_captcha($_REQUEST[‘captcha’]) ) {
    echo “captcha ok”;
    }else{
    echo “captcha false”;
    }

    thanks

    How are you sending other form data? If you are sending like $("form").serialize() then you will not need to include captcha value individually. In that case you can just use anr_verify_captcha().

    Your approach is also ok.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘adding captcha to custom form’ is closed to new replies.