Monday, January 23, 2012

Re: validates() in controller doesn't work

Hi

What do you mean when you say it doesn't work? Do you have an error message?

Best regards

On Mon, Jan 23, 2012 at 8:26 AM, Ivo Wolgensinger <wolgensinger@gmail.com> wrote:
Dear all

I have some difficulties to set up a proper validates()-function in
the Controller. Everything in the function works fine, exept the
validates() in the if construct. Here is my UserController, in which I
have to check an email entry with my EmailAddress-Model:
[code]
......
       function adduseremailsend () {  // sends the email for validate the
new email.
               if ($this->request->is('post')) {
                       $this->EmailAddress->set($this->data); // here another model is
loaded (we are in the UserController)
                       if ($this->EmailAddress->validates()) { // here is the validation,
but this don't work
                               $tomail = $this->data['User']['email'];
                               $email = new CakeEmail();
                               $email->config('smtp'); // here, we call the options in the file /
Config/email.php
                               $email->to($tomail);
                               $email->subject('Validate email');
                               $email->emailFormat('both');
                               $email->viewVars(array('token' =>
md5($tomail.'someSalt'.AuthComponent::user('id')), 'tomail' =>
$tomail, 'uid' => AuthComponent::user('id')));
                               $email->template('adduseremail'); // we call the template in app/
View/Emails/text/ and/or app/View/Emails/html/
                               if ($email->send()) {
                                       $this->Session->setFlash('Email with validation link sent to your
address.');
                               } else {
                                       $this->Session->setFlash('Email not sent');
                               }
                       } else {
                               $this->Session->setFlash('This was not an emailaddress.');
                       }
               }
               $this->redirect(array('controller' => 'users','action' =>
'profile'));
       }
......
[/code]

And here is my EmailAddress Model:
[code]
<?php

class EmailAddress extends AppModel {
   public $name = 'EmailAddress';

   public $validate = array(
       'email' =>  array(
           'email' => array(
                   'rule' => array('email', true),
                   'message' => 'Please make sure your email is
entered correctly.'
           ),
           'unique' => array(
                   'rule' => 'isUnique',
                   'message' => 'An entry with that emailaddress
already exists.'
           ),
           'required' => array(
                   'rule' => 'notEmpty',
                   'message' => 'Please enter your email.'
           )
       )
   );
}
?>
[/code]
As I know, the code in the EmailAddress Model works fine with other
projects. I think the error is in the UserController file.
Does anybody knows how to do that? As I said, everything works well
except the if-clause. And we are in the UserController and want to use
the EmailAddress Model.

Thank you very much for any help.

Ivo

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


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

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
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

No comments: