I'm looking for an OTRS "Best Practices" way to enable the reCAPTCHA (use Captcha::reCAPTCHA;) within OTRS, but only if the config item is set.
Thoughts?
How would I implement a conditional required module?
-
- Moderator
- Posts: 10170
- Joined: 04 May 2010, 18:38
- Znuny Version: 5.0.x
- Location: SouthWest Florida, USA
- Contact:
How would I implement a conditional required module?
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
-
- Znuny guru
- Posts: 5018
- Joined: 13 Mar 2011, 09:54
- Znuny Version: 6.0.x
- Real Name: Renée Bäcker
- Company: Perl-Services.de
- Contact:
Re: How would I implement a conditional required module?
Code: Select all
# check if captcha is enabled via sysconfig
if ( $Self->{ConfigObject}->Get( 'UseCAPTCHA' ) ) {
# load Module
$Self->{MainObject}->Require( 'Captcha::reCAPTCHA' );
# store a flag in the object to avoid function calls
$Self->{Captcha} = 1;
}
# ...
# in your subaction to show the form
if ( $Self->{Captcha} ) {
# set variable for use in template
$Param{...} = ...;
}
# something similar to check the captcha in an other subaction branch
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
-
- Moderator
- Posts: 10170
- Joined: 04 May 2010, 18:38
- Znuny Version: 5.0.x
- Location: SouthWest Florida, USA
- Contact:
Re: How would I implement a conditional required module?
reneeb, that's beautiful.
Although (maybe you might agree?) I shouldn't need a flag if I have a flag.
and probably I'll want to error out in a nice way if Require fails, but good enough to get me started.
Although (maybe you might agree?) I shouldn't need a flag if I have a flag.
Code: Select all
if ( $Self->{Captcha} ) {
Code: Select all
if ( $Self->{ConfigObject}->Get( 'UseCAPTCHA' ) ) {
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask