I would like to validate a field in a form - the username - to see if
it is already present in the database. I have it working, but in debug
mode I am getting a javascript warning.

First off, my code:

The ajax call in add.ctp:
[code]<?php echo $ajax->observeField('username', array('url' => '/
users/checkusername',
                                                                 'update' => 
'usernamestatus',
                                                                 'frequency' => 
2));[/code]

The users_controller.php function:
[code]function checkusername() {
                        $this->autoRender=false;
                        $this->data['User']['username'] = 
strtolower($this->data['User']
['username']);

                        if (!empty($this->data['User']['username'])) {

                                if 
($this->User->validates($this->data['User']['username']))
                                {
                                        echo "<span class=\"error\">Invalid 
userame</span>";
                                }
                                else
                                {
                                        $condition = array('User.username' => 
$this->data['User']
['username']);
                                        $a = $this->User->find($condition);

                                        if (!empty($a)) {
                                                echo "<span 
class=\"error\">Username already taken</span>";
                                        }
                                        else
                                        {
                                                echo "<span 
class=\"success\">Username available</span>";
                                        }
                                }
                        }
        }[/code]

The generated HTML code:
[code]new Form.Element.Observer('username', 2, function(element,
value) {new Ajax.Updater('usernamestatus','/users/checkusername',
{asynchronous:true, evalScripts:true,
parameters:Form.Element.serialize('username'), requestHeaders:['X-
Update', 'usernamestatus']})})
[/code]

And finally, the warning I am getting:
[code]Warning (2): array_key_exists() [function.array-key-exists]: The
second argument should be either an array or an object [CORE\cake\libs
\model\model.php, line 2205][/code]

Has anyone an idea of how to solve this? As is aparrent from the
error, I am supposed to pass an argument as an array but I have no
idea what.

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