This isn't too tricky to fix.
Essentially you want to reload the form if registration fails? Like
Paul said above, you need to be doing the validation in the Model, and
use the Model->validates() method to test for it.
So, if you build the validation criteria in the model (have a look at
the Book if you don't know how, it explains it well), then you need to
control registration using a simple if statement in the controller:
if($this->Model->validates()) {
//do registration logic here e.g.
$this->Model->create();
if($this->Model->save($this->data)) {
//do stuff for successful registration here
}
}
// since we didn't trigger the validates = true, the data didn't
validate so just reload the controller, which will be filled
automagically with
// validation errors
I hope that makes sense? Then making it reappear in the lightbox is
just a case of ensuring that your lightbox script supports loading new
content from within it. I like colorbox, personally, but there are
lots of great scripts!
Hope that helps,
J
On May 13, 8:43 am, sherzo <[email protected]> wrote:
> Hi Paul
>
> Thanks for your reply and the great comment about the validation. My main
> issue is, the registration form is included in a light box and after
> submission I dont like it to be redirected to another page in case of any
> error especially of user turned off the javascript in the browser !
>
> Thanks
> Sherry
>
>
>
>
>
> WebbedIT wrote:
>
> > Hmm, your doing all of your validation manually in the controller ...
> > this is supposed to be done automagically by the model when you save
> > the record.
>
> > Read the following through a couple of times:
>
> >http://book.cakephp.org/view/125/Data-Validation
>
> > The one thing you have to watch out for is the password field which is
> > automatically hashed by the Auth component, so to check if
> > password_confirm matches password you also need to hash the
> > password_confirm field. It's easy to do this using a custom
> > validation function such as
>
> > User Model:
> > ...
> > var $validate = array(
> > 'username' => array(
> > 'isUnique' => array(
> > 'rule' => 'isUnique',
> > 'message' => 'Sorry, this username has been taken, please try
> > another',
> > 'last' => true
> > ),
> > 'validChars' => array(
> > 'rule' => '/^[a-z0-9_]{1,}$/i',
> > 'message' => 'Can only include letters, numbers and underscores'
> > )
> > ),
> > 'password_confirm' => array(
> > 'notEmpty' => array(
> > 'rule' => array('notEmpty'),
> > 'message' => 'This field cannot be left blank',
> > 'on' => 'create',
> > 'last' => true
> > ),
> > 'confirm' => array(
> > 'rule' => array('validateConfirmPassword'),
> > 'message' => 'Password confirmation does not match'
> > )
> > )
> > );
>
> > function __validateConfirmPassword($field) {
> > $valid = false;
> > if ($this->data['User']['password'] ==
> > Security::hash(Configure::read('Security.salt') .
> > $field['password_confirm'])) {
> > $valid = true;
> > }
> > return $valid;
> > }
> > ...
>
> > HTH
>
> > Paul.
>
> > Check out the new CakePHP Questions sitehttp://cakeqs.organd 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 [email protected]
> > To unsubscribe from this group, send email to
> > [email protected] For more options, visit this group
> > athttp://groups.google.com/group/cake-php?hl=en
>
> --
> View this message in
> context:http://old.nabble.com/Dealing-with-forms%21%21%21%21%21-tp28541795p28...
> Sent from the CakePHP mailing list archive at Nabble.com.
>
> Check out the new CakePHP Questions sitehttp://cakeqs.organd 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 [email protected]
> To unsubscribe from this group, send email to
> [email protected] For more options, visit this group
> athttp://groups.google.com/group/cake-php?hl=en
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 [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en