21
JamesSAEP
Re: Frameworks Captcha
  • 2007/3/2 22:49

  • JamesSAEP

  • Just can't stay away

  • Posts: 732

  • Since: 2005/2/28


Well, I'm not sure what I'm doing wrong. Your settings are just like what I have and when I go to the register.php page, it is still the default page without the captcha info.

I have deleted template_c, cache and browser files!
I've modified two files:
1. register.php (with code you proviced)
2. class/xoopsformloader.php (with code you provided)

I've got to be missing!

22
skenow
Re: Frameworks Captcha
  • 2007/3/2 23:19

  • skenow

  • Home away from home

  • Posts: 993

  • Since: 2004/11/17


The other thing to note is the captcha field does not appear until the 2nd page of the process. Complete the first page of the form, then submit. Captcha will be on the next page.

23
jfmoore
Re: Frameworks Captcha
  • 2007/3/3 0:18

  • jfmoore

  • Quite a regular

  • Posts: 360

  • Since: 2004/6/6 5


Skenow,

I don't use 2.0.16. I'm still hoping someone will answer about 2.2.x. But I have compared the original register.php to the one you posted, and there are more differences than just adding the 'include' statement. It would be helpful if you would highlight the required changes in red as is usually done.

If I understood it better, I might even try it on a 2.2.4 site.

JFM
...

24
skenow
Re: Frameworks Captcha
  • 2007/3/3 1:06

  • skenow

  • Home away from home

  • Posts: 993

  • Since: 2004/11/17


@jfmoore - I've edited the above post to highlight the differences. phppp's example in the formcapthca.php file is complete - be sure to include the formcaptcha.php file, add the captcha element to the form, then add the captcha check to the form validation.

There are some very good file comparison utilities available to help you compare files and folders and find the differences. I use WinMerge

25
jfmoore
Re: Frameworks Captcha
  • 2007/3/3 2:23

  • jfmoore

  • Quite a regular

  • Posts: 360

  • Since: 2004/6/6 5


skenow-
You obviously know not to whom you speak. I hate to be dense, but, hey, if the shoe fits ...

You probably sense a question coming, and I am not one to disappoint. What, specifically, does this part mean?

Quote:

be sure to include the formcaptcha.php file,
add the captcha element to the form,
then add the captcha check to the form validation.


Jere
...

26
skenow
Re: Frameworks Captcha
  • 2007/3/3 17:06

  • skenow

  • Home away from home

  • Posts: 993

  • Since: 2004/11/17


Here goes - I hope I can make sense of this for you (and me!)

There are 3 parts to adding captcha to a form:
1. Providing the captcha functionality
2. Adding the captcha element to the form
3. Verification of the captcha entry

To add the captcha functionality to a form, you need to -
1. have the latest version of Frameworks (1.10) on your site, it includes a captcha folder.
2. add 'include_once XOOPS_ROOT_PATH."/Frameworks/captcha/formcaptcha.php";' to the page that creates the form. An alternative method would be to add this line to class/xoopsformloader.php, making the captcha function available for all forms loaded by Xoops

Next, you need to add the captcha element to the form. The basic method for doing this in a XOOPS form is to use this structure

$form->addElement(&$element, $required = false);

For a captcha element, the syntax looks like this -

$xoopsform->addElement(new XoopsFormCaptcha($caption, $name, $skipmember, $numchar, $minfontsize, $maxfontsize, $backgroundtype, $backgroundnum);

Putting this all together results in how phppp modified the register.php form (lines 150 - 153)
Quote:
if(@include_once XOOPS_ROOT_PATH."/Frameworks/captcha/formcaptcha.php") {
$cpatcha = new XoopsFormCaptcha();
echo $cpatcha->getCaption().": ".$cpatcha->render();
}


The final step is to verify the captcha entry when the form is submitted. The basic syntax is

if(@include_once XOOPS_ROOT_PATH."/Frameworks/captcha/captcha.php") {
$xoopsCaptcha = XoopsCaptcha::instance();
if(! $xoopsCaptcha->verify() ) {
echo $xoopsCaptcha->getMessage();
...
}
}


Again, using phppp's register.php, lines 177 - 182,
Quote:

if(@include_once XOOPS_ROOT_PATH."/Frameworks/captcha/captcha.php") {
$xoopsCaptcha = XoopsCaptcha::instance();
if(! $xoopsCaptcha->verify() ) {
$stop .= $xoopsCaptcha->getMessage()."
";
}
}


More about using the XoopsForm Library is in the dev.xoops.org wiki

All of this comes from reading the comments in formcaptcha.php (Frameworks/captcha/formcaptcha.php) and the documentation about XoopsForms on dev.xoops.org

That's about as far as I can go with this...

Hope it helps!

27
JamesSAEP
Re: Frameworks Captcha
  • 2007/3/5 14:17

  • JamesSAEP

  • Just can't stay away

  • Posts: 732

  • Since: 2005/2/28


skenow -
Thank you for all your info on this. From the beginning, this was working for me, I just never pressed "submit" to go to the second page.

Much appreciated!

J

28
JamesSAEP
Re: Frameworks Captcha
  • 2007/3/5 15:17

  • JamesSAEP

  • Just can't stay away

  • Posts: 732

  • Since: 2005/2/28


I have made the Captcha hack part of a new install package.
You can download and read about it HERE.

29
cutley
Re: Frameworks Captcha
  • 2007/7/18 14:16

  • cutley

  • Just popping in

  • Posts: 38

  • Since: 2005/11/27


Sorry to bump this up but I really need some help.

Iv been trying to get this to work for hours with no luck.

I want to get it to work with 2.2

I can get the form element to be generated fine but it doesnt check for it be valid.

Iv put this:


// $Id: register.php,v 1.1.2.13.2.1 2005/09/18 13:59:36 mithyt2 Exp $
//  ------------------------------------------------------------------------ //
//                XOOPS - PHP Content Management System                      //
//                    Copyright (c) 2000 XOOPS.org                           //
//                                                    //
//  ------------------------------------------------------------------------ //
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  You may not change or alter any portion of this comment or credits       //
//  of supporting developers from this source code or any supporting         //
//  source code which is considered copyrighted (c) material of the          //
//  original comment or credit authors.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
//  ------------------------------------------------------------------------ //
include '../../mainfile.php';
[
color=CC0000]include_once XOOPS_ROOT_PATH.'/Frameworks/captcha/formcaptcha.php';[/color]
include_once 
'include/functions.php';
$myts =& MyTextSanitizer::getInstance();



if (empty(
$xoopsModuleConfig['allow_register'])) {
    
redirect_header('../../index.php'6_PROFILE_MA_NOREGISTER);
    exit();
}
include 
XOOPS_ROOT_PATH.'/header.php';

$member_handler =& xoops_gethandler('member');
$newuser =& $member_handler->createUser();
$op = !isset($_POST['op']) ? 'register' $_POST['op'];
if (
$op != "register") {
    
$newuser->setVar('uname', isset($_POST['uname']) ? trim($_POST['uname']) : '');
    
$newuser->setVar('loginname', isset($_POST['loginname']) ? trim($_POST['loginname']) : '');
    
$newuser->setVar('email', isset($_POST['email']) ? trim($_POST['email']) : '');

    
//Dynamic fields
    
$profile_handler =& xoops_gethandler('profile');
    
// Get fields
    
$fields =& $profile_handler->loadFields();
    if (
count($fields) > 0) {
        foreach (
array_keys($fields) as $i) {
            
$fieldname $fields[$i]->getVar('field_name');
            if (
$fields[$i]->getVar('field_register') && isset($_POST[$fieldname])) {
                
$newuser->setVar($fieldname$_POST[$fieldname]);
            }
        }
    }

    
$vpass = isset($_POST['vpass']) ? $myts->stripSlashesGPC($_POST['vpass']) : '';
    
$agree_disc = (isset($_POST['agree_disc']) && intval($_POST['agree_disc'])) ? 0;
}
switch ( 
$op ) {
    case 
'newuser':
    if (!
$GLOBALS['xoopsSecurity']->check()) {
        echo 
implode(''$GLOBALS['xoopsSecurity']->getErrors());
        break;
    }
    
$newuser->setVar('pass', isset($_POST['pass']) ? md5(trim($_POST['pass'])) : '');
    
$stop '';
    if (
$xoopsModuleConfig['display_disclaimer'] != && $xoopsModuleConfig['disclaimer'] != '') {
        if (empty(
$agree_disc)) {
            
$stop .= _PROFILE_MA_UNEEDAGREE.'';
        }
    }
    if (!empty(
$xoopsModuleConfig['minpass']) && strlen(trim($_POST['pass'])) < $xoopsModuleConfig['minpass']) {
        
$stop .= sprintf(_PROFILE_MA_PWDTOOSHORT,$xoopsModuleConfig['minpass'])."";
    }
    
$stop .= userCheck($newuser);
    if (empty(
$stop)) {
    [
color=CC0000]if(@include_once XOOPS_ROOT_PATH."/Frameworks/captcha/formcaptcha.php") {
            
$cpatcha = new XoopsFormCaptcha();
            echo 
$cpatcha->getCaption().": ".$cpatcha->render()."";
        }[/
color]
        echo 
_PROFILE_MA_USERNAME.": ".$newuser->getVar('loginname')."";
        echo 
_PROFILE_MA_EMAIL.": ".$newuser->getVar('email')."";
        echo 
_PROFILE_MA_DISPLAYNAME.": ".$newuser->getVar('uname')."";
        
$profile_handler =& xoops_gethandler('profile');
        
// Get fields
        
$fields =& $profile_handler->loadFields();
        if (
count($fields) > 0) {
            foreach (
array_keys($fields) as $i) {
                
$fieldname $fields[$i]->getVar('field_name');
                if (
$fields[$i]->getVar('field_register') && isset($_POST[$fieldname])) {
                    
$value $newuser->getVar($fieldname);
                    if (
is_array($value)) {
                        
$values = array();
                        
$options $fields[$i]->getVar('field_options');
                        foreach (
$value as $thisvalue) {
                            
$values $options[$thisvalue];
                        }
                        
$value implode(', '$values);
                    }
                    echo 
$fields[$i]->getVar('field_title').": ".$value."";
                }
            }
        }
        
//hidden POST form with variables
        
include_once 'include/forms.php';
        
$finish_form =& getFinishForm($newuser$vpass);
        
$finish_form->display();
    } else {
        echo 
"$stop
";
        include_once 
'include/forms.php';
        
$reg_form =& getRegisterForm($newuser);
        
$reg_form->display();
    }
    break;
    
    case 
'finish':
    if (!
$GLOBALS['xoopsSecurity']->check()) {
        echo 
implode(''$GLOBALS['xoopsSecurity']->getErrors());
        break;
    }
    [
color=CC0000]if(@include_once XOOPS_ROOT_PATH."/Frameworks/captcha/captcha.php") {
    
$xoopsCaptcha XoopsCaptcha::instance();
        if(! 
$xoopsCaptcha->verify() ) {
        
$stop .= $xoopsCaptcha->getMessage()."";
        }
    }[/
color]
    
$stop '';
    if (
$xoopsModuleConfig['display_disclaimer'] != && $xoopsModuleConfig['disclaimer'] != '') {
        if (empty(
$agree_disc)) {
            
$stop .= _PROFILE_MA_UNEEDAGREE.'';
        }
    }
    
$stop userCheck($newuser);
    if ( empty(
$stop) ) {
        
$newuser->setVar('pass'$_POST['pass']);
        
$newuser->setVar('user_avatar','blank.gif');
        
$actkey substr(md5(uniqid(mt_rand(), 1)), 08);
        
$newuser->setVar('actkey'$actkey);
        
$newuser->setVar('user_regdate'time());
        if (
$xoopsModuleConfig['activation_type'] == 1) {
            
$newuser->setVar('level'1);
        }

        
$profile_handler =& xoops_gethandler('profile');
        
// Get fields
        
$fields =& $profile_handler->loadFields();
        if (
count($fields) > 0) {
            foreach (
array_keys($fields) as $i) {
                
$fieldname $fields[$i]->getVar('field_name');
                if (
$fields[$i]->getVar('field_register') && isset($_POST[$fieldname])) {
                    
$newuser->setVar($fieldname$_POST[$fieldname]);
                }
            }
        }
        if (!
$member_handler->insertUser($newuser)) {
            echo 
_PROFILE_MA_REGISTERNG;
            echo 
implode(''$newuser->getErrors());
            break;
        }
        
$newid $newuser->getVar('uid');
        if (!
$member_handler->addUserToGroup(XOOPS_GROUP_USERS$newid)) {
            echo 
_PROFILE_MA_REGISTERNG;
            break;
        }
        
        
//Welcome PM Hack start
        //Yeah,already defined above^^
        // $newid = $newuser->getVar('uid');
        
$pm_handler =& xoops_gethandler('privmessage');
        
$pm =& $pm_handler->create();
        
$pm->setVar("subject""Welcome to Swift");
        
$pm->setVar("msg_text""Thanks for taking the time to register on the site. You can now reply to/comment articles and use the forum.
        If you are based in/around Essex please [url=http://swift-freedom.com/x/essex/modules/articles/article.php?id=19]add yourself to the location directory[/url].
        If you have any problems with the site please email swift@swift-freedom.com"
);
        
//Newuser's id
        
$pm->setVar("to_userid"$newid);
        
// Admin's id,1 in my case
        
$pm->setVar("from_userid"1);
        if (!
$pm_handler->insert($pm)) {
        
// echo "Failed to send Welcome Private Message!!";
        // No need to echo this failure-message here,I think so!!...Just optional^^
        
}
        
//Welcome PM Hack end

        
if ($xoopsModuleConfig['activation_type'] == 1) {
            
redirect_header(XOOPS_URL.'/index.php'4_PROFILE_MA_ACTLOGIN);
        }
        if (
$xoopsModuleConfig['activation_type'] == 0) {
            
$xoopsMailer =& getMailer();
            
$xoopsMailer->useMail();
            
$xoopsMailer->setTemplate('register.tpl');
            
$xoopsMailer->setTemplateDir(XOOPS_ROOT_PATH."/modules/profile/language/".$xoopsConfig['language']."/mail_template");
            
$xoopsMailer->assign('SITENAME'$xoopsConfig['sitename']);
            
$xoopsMailer->assign('ADMINMAIL'$xoopsConfig['adminmail']);
            
$xoopsMailer->assign('SITEURL'XOOPS_URL."/");
            
$xoopsMailer->setToUsers(new XoopsUser($newid));
            
$xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
            
$xoopsMailer->setFromName($xoopsConfig['sitename']);
            
$xoopsMailer->setSubject(sprintf(_PROFILE_MA_USERKEYFOR$newuser->getVar('uname')));
            if ( !
$xoopsMailer->send() ) {
                echo 
_PROFILE_MA_YOURREGMAILNG;
            } else {
                echo 
_PROFILE_MA_YOURREGISTERED;
            }
        } elseif (
$xoopsModuleConfig['activation_type'] == 2) {
            
$xoopsMailer =& getMailer();
            
$xoopsMailer->useMail();
            
$xoopsMailer->setTemplate('adminactivate.tpl');
            
$xoopsMailer->setTemplateDir(XOOPS_ROOT_PATH."/modules/profile/language/".$xoopsConfig['language']."/mail_template");
            
$xoopsMailer->assign('USERNAME'$newuser->getVar('uname'));
            
$xoopsMailer->assign('USEREMAIL'$newuser->getVar('email'));
            
$xoopsMailer->assign('USERACTLINK'XOOPS_URL.'/modules/profile/activate.php?op=actv&id='.$newid.'&actkey='.$actkey);
            
$xoopsMailer->assign('SITENAME'$xoopsConfig['sitename']);
            
$xoopsMailer->assign('ADMINMAIL'$xoopsConfig['adminmail']);
            
$xoopsMailer->assign('SITEURL'XOOPS_URL."/");
            
$member_handler =& xoops_gethandler('member');
            
$xoopsMailer->setToGroups($member_handler->getGroup($xoopsModuleConfig['activation_group']));
            
$xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
            
$xoopsMailer->setFromName($xoopsConfig['sitename']);
            
$xoopsMailer->setSubject(sprintf(_PROFILE_MA_USERKEYFOR$newuser->getVar('uname')));
            if ( !
$xoopsMailer->send() ) {
                echo 
_PROFILE_MA_YOURREGMAILNG;
            } else {
                echo 
_PROFILE_MA_YOURREGISTERED2;
            }
        }
        if (
$xoopsModuleConfig['new_user_notify'] == && !empty($xoopsModuleConfig['new_user_notify_group'])) {
            
$xoopsMailer =& getMailer();
            
$xoopsMailer->useMail();
            
$member_handler =& xoops_gethandler('member');
            
$xoopsMailer->setToGroups($member_handler->getGroup($xoopsModuleConfig['new_user_notify_group']));
            
$xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
            
$xoopsMailer->setFromName($xoopsConfig['sitename']);
            
$xoopsMailer->setSubject(sprintf(_PROFILE_MA_NEWUSERREGAT,$xoopsConfig['sitename']));
            
$xoopsMailer->setBody(sprintf(_PROFILE_MA_HASJUSTREG$newuser->getVar('uname')));
            
$xoopsMailer->send();
        }
    } else {
        echo 
"$stop
";
        include_once 
'include/forms.php';
        
$reg_form =& getRegisterForm($newuser);
        
$reg_form->display();
    }
    break;
    
    case 
'register':
    default:
    include_once 
'include/forms.php';
    
$reg_form =& getRegisterForm($newuser);
    
$reg_form->display();

    break;
}
include 
XOOPS_ROOT_PATH.'/footer.php';
?>


p.s why am i not notified of new user registeration if it is set to automatic activation.
- - - - -
xoops FTW

30
skenow
Re: Frameworks Captcha
  • 2007/7/18 18:23

  • skenow

  • Home away from home

  • Posts: 993

  • Since: 2004/11/17


Try this solution Re: Captcha to register page.

Login

Who's Online

302 user(s) are online (224 user(s) are browsing Support Forums)


Members: 0


Guests: 302


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits