[code]
public function signup() {
if ($this->request->is('post')) {
$this->User->set($this->data);
if ($this->User->validates('email')) { // this validation does not
work!
$this->Session->setFlash('This is a valid emailaddress.');
} else {
$this->Session->setFlash('This is NOT a valid emailaddress.');
}
}
}
[/code]
If I past 'asdfasdf' in the emailfield, then I get a Flash Message
'This is a valid emailaddress.'....
The system is pretending to test the field, but it returns true
everytime.
Huh, I don't know how to solve this problem. I'm using cakephp 2
Kind regards
On 23 Jan., 13:17, Florin Trifu <florin.catalin.tr...@gmail.com>
wrote:
> 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 <wolgensin...@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 sitehttp://ask.cakephp.organd 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
> > athttp://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:
Post a Comment