Display Cb Antispam elsewhere

7 years 9 months ago - 7 years 9 months ago #283979 by poml
Display Cb Antispam elsewhere was created by poml
Hi, I would like to display the CB Antispam field in a custom built form. Like it is displayed on the registration page. How would I do that? A field replacement like antispam_captcha does not seem to work.

Or, related question: If I cannot display it elsewhere, is it possible somehow to deactivate this plugin temporarily on a certain page? Or by some php code or replacement?

Or is it possible to get the $code of the captcha? Then I could auto-fill it in --> problem also solved.

Please Log in to join the conversation.

7 years 9 months ago #283985 by krileon
Replied by krileon on topic Display Cb Antispam elsewhere
You can output CB AntiSpam captcha using the below usage.

$_PLUGINS->loadPluginGroup( 'user' );

$captcha				=	$_PLUGINS->trigger( 'onGetCaptchaHtmlElements', array( false ) );

if ( ! empty( $captcha ) ) {
	$captcha			=	$captcha[0];
}

The above gives you an array of the captcha image and the input. You can display them however you like. It's validated during your POST process using the below.

$_PLUGINS->loadPluginGroup( 'user' );

$_PLUGINS->trigger( 'onCheckCaptchaHtmlElements', array() );

if ( $_PLUGINS->is_errors() ) {
	// CAPTCHA FAILED
}


Why is this a problem? What are you trying to do? You don't have to use the captcha field if you don't want registration captcha.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

7 years 9 months ago #283994 by poml
Replied by poml on topic Display Cb Antispam elsewhere
Ok, thanks a lot for the code.

What I am doing is registering a user using a custom script and it used to work fine, but now that I have antispam installed for the "normal" registration my script stopped working. So I figured I had two options:
1) Display the capture and let the user solve it, or
2) let the script solve it.
What I came up with during the weekend is:
global $_CB_framework, $_CB_database, $ueConfig, $_PLUGINS;
[...]
require_once JPATH_SITE.'/components/com_comprofiler/plugin/user/plug_cbantispam/cbantispam.php';
$captcha = cbantispamCaptcha::getInstance( 'antispam_captcha' , 'internal');
$code = $captcha->getCaptchaCode();
$data['antispam_captcha'] = $code;
It generates a captcha and saves the code to $data and I can save my user registration.

Does this make sense? Or is the code crap?

Please Log in to join the conversation.

7 years 9 months ago - 7 years 9 months ago #284004 by krileon
Replied by krileon on topic Display Cb Antispam elsewhere

Does this make sense? Or is the code crap?

No, and yes. I've provided above the way to safely output the captcha using the legacy trigger. The alternative is to do a proper plugin load (do not include plugin files directly!) and then utilize that plugins API directly. To load plugins you use the below.

$_PLUGINS->loadPluginGroup( 'user' );

A specific plugin can be loaded with the below.

$_PLUGINS->loadPluginGroup( null, 'cbantispam' );

Note that even running this is not a guarantee. If you use API for a plugin that lets say is unpublished you'll fatal error as it won't load. You need to do class exists checks to ensure the class you're calling was loaded.

What I am doing is registering a user using a custom script and it used to work fine, but now that I have antispam installed for the "normal" registration my script stopped working. So I figured I had two options:

What are you trying to do with your custom form that requires you to code all of this? You can condition fields to show/hide using CB Conditional and CB Auto Actions can be used to extend registration with functionality that may not exist (it can exit the display with the form display trigger and extend the storage on the after registration triggers).


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

7 years 9 months ago #284017 by poml
Replied by poml on topic Display Cb Antispam elsewhere
Ok, thanks. I will update my code and look into CB conditionals. You mean I could just hide the antispam fields?

Please Log in to join the conversation.

7 years 9 months ago #284041 by krileon
Replied by krileon on topic Display Cb Antispam elsewhere
You'd use CB Conditionals to have a more customized CB registration form instead of trying to code a custom form. I could suggest further usage examples, but you'd need to further explain what you need a custom registration form for. Even if you need a more customized registration form there is likely better alternatives to coding your own like usage of CB Profile Pro (3rd party plugin).


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.235 seconds

Facebook Twitter LinkedIn