New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recaptcha No Longer Loads in Standard Contact Form after Upgrading from 3.4.8 to 3.5.0 #9681

Closed
leskiapo opened this Issue Mar 31, 2016 · 6 comments

Comments

Projects
None yet
6 participants
@leskiapo

leskiapo commented Mar 31, 2016

Steps to reproduce the issue

Upgrade to 3.5.0 or install 3.5.0. Open standard contact form with Google Recaptcha enabled.

Expected result

Google Recaptcha should load/display.

Actual result

Google Recaptcha does not load/display.

System information (as much as possible)

Joomla 3.5.0 (either upgraded from earlier version or clean install)

Additional comments

Neither the label nor the recaptcha load. On all sites tested, recaptcha loaded as expected until upgrade to 3.5.0.

@brianteeman

This comment has been minimized.

Show comment
Hide comment
@brianteeman

brianteeman Mar 31, 2016

Contributor

Please can you test with 3.5.1 release candidate 2 as there were some fixes made to the recapatcha that I think have been resolved https://github.com/joomla/joomla-cms/releases/tag/3.5.1-rc2


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9681.

Contributor

brianteeman commented Mar 31, 2016

Please can you test with 3.5.1 release candidate 2 as there were some fixes made to the recapatcha that I think have been resolved https://github.com/joomla/joomla-cms/releases/tag/3.5.1-rc2


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9681.

@ahvink

This comment has been minimized.

Show comment
Hide comment
@ahvink

ahvink Mar 31, 2016

Fix to make your custom component work again with joomla's recaptcha:

<?php else : ?>
     <div class="g-recaptcha" data-sitekey=“YOUR_SITE_KEY" data-theme="light" data-size="normal"></div>
<?php endif; ?>

This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9681.

ahvink commented Mar 31, 2016

Fix to make your custom component work again with joomla's recaptcha:

<?php else : ?>
     <div class="g-recaptcha" data-sitekey=“YOUR_SITE_KEY" data-theme="light" data-size="normal"></div>
<?php endif; ?>

This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9681.
@leskiapo

This comment has been minimized.

Show comment
Hide comment
@leskiapo

leskiapo Mar 31, 2016

That fixes the problem. I learned more about the issue after I posted this message. As it turns out, unless "Captcha - ReCaptcha" is set under Global Configuration > Site > Default Captcha, even though under "Global Configuration > Contacts > Form > Allow Captcha on Contact" was set to Captcha - Recaptcha, it would not work. You had to have it set to "Captcha - ReCaptcha" under the Site tab (Global Config). The patch fixed this and it now behaves as it did before the upgrade to 3.5.0.
Thanks!


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9681.

leskiapo commented Mar 31, 2016

That fixes the problem. I learned more about the issue after I posted this message. As it turns out, unless "Captcha - ReCaptcha" is set under Global Configuration > Site > Default Captcha, even though under "Global Configuration > Contacts > Form > Allow Captcha on Contact" was set to Captcha - Recaptcha, it would not work. You had to have it set to "Captcha - ReCaptcha" under the Site tab (Global Config). The patch fixed this and it now behaves as it did before the upgrade to 3.5.0.
Thanks!


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9681.

@fguyon

This comment has been minimized.

Show comment
Hide comment
@fguyon

fguyon Apr 9, 2016

Hi
Thanx for the fix, but in which file to paste it ?


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9681.

fguyon commented Apr 9, 2016

Hi
Thanx for the fix, but in which file to paste it ?


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9681.

@ahvink

This comment has been minimized.

Show comment
Hide comment
@ahvink

ahvink Apr 9, 2016

You need to change the html with which you call joomla's recaptcha plugin. So you need to edit your form's default.php file so it will show the recaptcha irrespective of your joomla version like this:

 <?php if (version_compare(JVERSION, '3.5', '<')) : ?>
       <div id="dynamic_recaptcha_1"></div>
 <?php else : ?>
       <div class="g-recaptcha" data-sitekey="YOUR_SITE_KEY" data-theme="light" data-size="normal"></div>
 <?php endif; ?>

This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9681.

ahvink commented Apr 9, 2016

You need to change the html with which you call joomla's recaptcha plugin. So you need to edit your form's default.php file so it will show the recaptcha irrespective of your joomla version like this:

 <?php if (version_compare(JVERSION, '3.5', '<')) : ?>
       <div id="dynamic_recaptcha_1"></div>
 <?php else : ?>
       <div class="g-recaptcha" data-sitekey="YOUR_SITE_KEY" data-theme="light" data-size="normal"></div>
 <?php endif; ?>

This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9681.
@ggppdk

This comment has been minimized.

Show comment
Hide comment
@ggppdk

ggppdk Apr 9, 2016

Contributor

@ahvink

  • if you want to add a captcha field into a form without using the form element 'captcha' (via the XML of your form)

but you would like to instatiate it manually (and also do validation manually on the controller save task)
it is better to avoid adding the HTML / JS / etc of the captcha directly

  • it may break in the future

Instead the API display() method should be used
something like this will work with (please correct any syntax or other errors ...):

  • any captcha plugin
  • both J3.4.x / J3.5.x and future versions ?

FORM

$captcha_field_html = '';

// Use configured captcha plugin
if ( $c_plugin = JFactory::getApplication()->getCfg('captcha') )
{
    // Try to load the configured captcha plugin, (check if disabled or uninstalled)
    // Joomla will enqueue an error message if needed
    $captcha_obj = JCaptcha::getInstance($c_plugin, array('namespace' => 'my_component_form'));

    $captcha_field_html = $captcha_obj  ?
        $captcha_obj->display('captcha_field_name', 'captcha_tag_id', ' captcha_outer_class ')  :
        '' ;
}

CONTROLLER save task


// ** Extra validation for manually added captcha
// Use configured captcha plugin
if ( $c_plugin = JFactory::getApplication()->getCfg('captcha') ) 
{
    // Get captcha value
    $c_value = $app->input->get('captcha_field_name', null, 'STRING');

    // Get captch object instance
    $captcha_obj = JCaptcha::getInstance($c_plugin, array('namespace' => 'my_component_form'));

    // Validate catcha
    if (!$captcha_obj->checkAnswer($c_value))
    {
        // Get the captcha validation message and push it out to the user
        // but default error message is not good ? maybe use custom here
        $error = $captcha_obj->getError();
        $app->enqueueMessage($error instanceof Exception ? $error->getMessage() : $error, 'error');

        // Set POST form data into the session, so that they get reloaded
        $app->setUserState($form->option.'.edit.'.$form->context.'.data', $data);

        // Redirect back to the component form
        $this->setRedirect( '...' );
        return false;
    }
}
Contributor

ggppdk commented Apr 9, 2016

@ahvink

  • if you want to add a captcha field into a form without using the form element 'captcha' (via the XML of your form)

but you would like to instatiate it manually (and also do validation manually on the controller save task)
it is better to avoid adding the HTML / JS / etc of the captcha directly

  • it may break in the future

Instead the API display() method should be used
something like this will work with (please correct any syntax or other errors ...):

  • any captcha plugin
  • both J3.4.x / J3.5.x and future versions ?

FORM

$captcha_field_html = '';

// Use configured captcha plugin
if ( $c_plugin = JFactory::getApplication()->getCfg('captcha') )
{
    // Try to load the configured captcha plugin, (check if disabled or uninstalled)
    // Joomla will enqueue an error message if needed
    $captcha_obj = JCaptcha::getInstance($c_plugin, array('namespace' => 'my_component_form'));

    $captcha_field_html = $captcha_obj  ?
        $captcha_obj->display('captcha_field_name', 'captcha_tag_id', ' captcha_outer_class ')  :
        '' ;
}

CONTROLLER save task


// ** Extra validation for manually added captcha
// Use configured captcha plugin
if ( $c_plugin = JFactory::getApplication()->getCfg('captcha') ) 
{
    // Get captcha value
    $c_value = $app->input->get('captcha_field_name', null, 'STRING');

    // Get captch object instance
    $captcha_obj = JCaptcha::getInstance($c_plugin, array('namespace' => 'my_component_form'));

    // Validate catcha
    if (!$captcha_obj->checkAnswer($c_value))
    {
        // Get the captcha validation message and push it out to the user
        // but default error message is not good ? maybe use custom here
        $error = $captcha_obj->getError();
        $app->enqueueMessage($error instanceof Exception ? $error->getMessage() : $error, 'error');

        // Set POST form data into the session, so that they get reloaded
        $app->setUserState($form->option.'.edit.'.$form->context.'.data', $data);

        // Redirect back to the component form
        $this->setRedirect( '...' );
        return false;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment