Hi,
I was doing a simple signup form. I am not getting the validation
error msg when they occur. If I enter data in the form that will cause
validation error nothing will happen but if the data is valid
according to my validation rules then they are inserted into the
database.
My code is as follows

Model

class User extends AppModel {
        var $name = "User";
        var $validate = array(
                "users_name" => array("rule" => "alphaNumeric","required" =>
true,"allowEmpty"=>false,"message" => "Alphabets and numbers only"),
                "users_email" => array(
                                                
"email"=>array("rule"=>"email","message"=>"Invalid email
address","required" => true,"allowEmpty"=>false),
                                                "unique"=>array("rule"=>array
("validateUniqueEmail"),"message"=>"This Email is already in
use","required" => true,"allowEmpty"=>false)),
        "users_password" => array("rule" => array
("confirmPassword","password"),"required"=>true,"allowEmpty"=>false,"message"
=> "Password do not match"),
                "password_confirm" => array("rule" => "alphaNumeric","required" 
=>
true)
        );

         function validateUniqueEmail(){
                 $error=0;
                 $someone = $this->findByUsers_email($this->data['User']
['users_email']);
                 if (isset($someone['User']))
                 {
                        $error++;
                 }
                 return $error==0;
         }

        function confirmPassword($data) {
                $valid = false;
                if ($data['users_password'] == $this->data['User']
['password_confirm']) {
                        $valid = true;
                }
                return $valid;
        }
}


Controller

class UsersController extends AppController
{
        var $name = "Users";
        var $helpers = array("Html","Form");
        var $components = array('Security');

        function beforeFilter(){
                $this->set("p1", $this->name);
        }

        function signup(){
                $this->set("p2", __FUNCTION__);
                if (!empty($this->data['user'])){
                        if ($this->User->save($this->data['user'])){
                                $this->flash(debug($this->data), 
'/users/signup');
                        }
                }
        }

View

<?echo $form->create('user', array('action' => 'signup'));?>
<fieldset>
        <legend>Signup</legend>
    <?php
                echo $form->input('user.users_name',array("label"=>"Name:"));

                echo $form->input('user.users_email',array("label"=>"Email:"));

                echo $form->input('user.users_password',array
("label"=>"Password:","type"=>"password"));

                echo 
$form->input('user.password_confirm',array('label'=>'Password
Confirm:','type'=>'password'));

        ?>
</fieldset>
<?echo $form->end("Sign Up");?>


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to