Life, SAP, Consulting, Programming, Coding, ASP.NET, Sharepoint, MVC, Javascript, PHP, WebDesign, CSS, HTML

Posts tagged ‘register form’

CakePHP set validate from Controller

I am still new to CakePHP. I need an app that allow people to login with both Social Authentication and built-in authentication. When mapping new user from social site, there are some fields can be empty. For example, username. It’s sometimes empty. But it will be required when user register your site. So, how to output and let user know that your it is required?

My solution is to create a function inside Controller, which will be called from register form output function.

Here is the code:

private function _buildValidate(){
$this->User->validate[‘username’] = array(‘required’ => true);
$this->User->validate[‘name’] = array(‘required’ => true);
$this->User->validate[’email’] = array(‘rule’ => ’email’, ‘required’ => true);
$this->User->validate[‘password’] = array(‘rule’ => array(‘minLength’, ‘6’),
‘required’ => true,
‘message’ => ‘Minimum 6 characters long’);
$this->User->validate[‘birthday’] = array(‘rule’ => ‘date’, ‘required’ => true);
$this->User->validate[‘gender’] = array(‘required’ => true);
$this->User->validate[‘city_id’] = array(‘required’ => true);

Woawo!!! Cake is on the way to be baked:)