Skip to content

Undefined variable: captcha in my view #2

Description

ahoy,

i'm trying to implement your component but i've a little issue.

here's my code on CommentController.php

class CommentsController extends AppController {

public $name = 'Comments';
public $helpers = array('Html', 'Form', 'Session');
public $components = array('MathCaptcha','RequestHandler');

public function add($post_id = null) {
            $this->set('captcha', $this->MathCaptcha->getCaptcha());
    if ($this->request->is('post')) {
        $this->Comment->set(array('post_id'=>$post_id));
        $this->request->data['Comment']['ip'] = $this->RequestHandler->getClientIp();

  if ($this->MathCaptcha->validate($this->request->data['Comment']['captcha'])) {
            $this->Session->setFlash("ok.","notif");
            $this->redirect(array('controller' => 'posts', 'action' => 'view', $post_id));
        } else {
             $this->Session->setFlash("ko.","notif");
        }
    }
}

}

and my view

Form->input('captcha', array('label' => 'Calculate this: '.$captcha)); ?>

but when i refresh i've an error who say:

Notice (8): Undefined variable: captcha [APP\View\Elements\newcomment.ctp, line 13]
(my line 13 is the line before

don't know why sadly ... can you please help me?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions