klark
klark

Reputation: 494

Cakephp makes a unique key validation that I did not ask for

I have a simple table where one of the field is country

It is not defined as unique key in the database and when I try to insert a record with the same country directly in MySql , the record is inserted without error. Fine.

But when I tried to insert through a edit screen in my Cakephp application, I got the error message on the country field 'Alphanumeric' which does not correspond to the reality because if I enter

for example: United States which is a country of another existing record, I got the error, if I enter xxxxx, the system accept to save the record. THat's is why I suspect that there is a check on unique Key.

My model for this field is the following

'country' => array(
            'notempty' => array(
                'rule' => array('notempty'),

            ),
            'alphanumeric' => array(
                'rule' => array('alphanumeric'),
                            ),
        )

Do you have any idea ? Is there another place where I should check ?

Upvotes: 0

Views: 84

Answers (2)

Indrajeet Singh
Indrajeet Singh

Reputation: 2989

**Use this code for unique validation form in cakephp.........**
$validator = $this->validator();
$validator['username'] = array(
    'unique' => array(
        'rule' => 'isUnique',
        'required' => 'create'
    ),
    'alphanumeric' => array(
        'rule' => 'alphanumeric'
    )
);

Upvotes: 0

ADmad
ADmad

Reputation: 8100

"United States" contains a space. The alphanumeric rule won't validate strings with space.

Upvotes: 2

Related Questions