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

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:)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: