Tuesday, November 30, 2010

Problem with Math Captcha component @ 1.3.6

Hello, i trying to use this small piece of code

http://jamienay.com/2009/06/math-captcha-component/

here its my code:
###############################################################

MODEL:

class Contact extends AppModel {
var $name = 'Contact';
var $useTable = false;

var $_schema = array(
'name' =>array('type' => 'string', 'length' => 100),
'email' =>array('type' => 'string', 'length' => 255),
'subject' =>array('type' => 'string', 'length' => 255),
'message' =>array('type' => 'text')
);

var $validate = array(
'name' => array('minLength' => array('rule' =>
array('minLength', 3))),
'email' => array('email' => array('rule' => 'email')),
'subject' => array('notempty' => array('rule'=>'notempty')),
'message' => array('minLength' => array('rule' =>
array('minLength', 60)))
);

}
###########################################################

Controller:
....
var $components = array('RequestHandler', 'Email', 'Session',
'MathCaptcha');

function index() {
$this->set('controller_name', __('Contact',true));
$this->set('action_name', __('Index',true));
if ($this->RequestHandler->isPost()) {
$this->Contact->set($this->data);
if ($this->MathCaptcha->validates($this->data['Contact']
['security_code'])) {
if ($this->Contact->validates()) {
$this->Email->to =
Configure::read('Setting.Site.email') ;
$this->Email->subject = $this->data['Contact']
['subject'];
$this->Email->from = $this->data['Contact']['email'];
$this->Email->send($this->data['Contact']['message']);
}

}else {
$this->Session->setFlash(__('Please enter the correct
answer to the math question.', true));
}
}
$this->set('mathCaptcha', $this->MathCaptcha-
>generateEquation());
}

######################################################

view

<?php
echo $this->Form->input('name',array('label'=>__('Your
Name',true),'error'=>array('minLength'=>__('You must enter your full
name!',true))));
echo $this->Form-
>input('email',array('error'=>array('email'=>__('Please enter your
valid email!',true))));
echo $this->Form->input('subject',array('options'=>array(null
=>__('-- Choose One --',true),

__('Jobs',true)=>__('Jobs',true),

__('Orders',true)=>__('Orders',true),

__('Products',true)=>__('Products',true),

__('Brands',true)=>__('Brands',true),

__('Services',true)=>__('Services',true),

__('Partners',true)=>__('Partner',true),

__('Promotion',true)=>__('Promotion',true),

__('Other',true)=>__('Other',true)),
'label'=>__('Type of
message',true),

'error'=>array('notempty'=>__('Please choose one',true))));
echo $this->Form-
>input('message',array('type'=>'textarea','label'=>__('Message',true),'error'=>array('minLength'=>__('Your
message is to short!',true))));
echo $form->input('security_code', array('label' => __('Please
Enter the Sum of ',true) . $mathCaptcha));
?>


I detected a problem in the components, function registerAnswer not
work as intended, that does not set the session.

Help me to solve a problem:)

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: