In my application, whenever users input, I need to check if some
fields are duplicate frequently (for example, user name, email, course
title, etc). I am using AJAX to do this.

The problem is, I find I am repeating a method again and again in
various controllers.

Basically, in my view, I have something like:

echo $html->input('User/username', array('id'=>'username',
'size'=>'50'));

//User/username is just an example, it can be User/email, Course/
title, etc

<div id="err">
        <?php
        echo $ajax->observeField('username', array('update'=>'err',
'url'=>"/users/checkduplicate", 'frequency'=>1));
                 ?>
         </div>

In my User cotroller, I have:

  function checkduplicate()
    {
        $this->autoRender=false;
        if (!empty($this->data['User']['username']))
        {    $condition=array('username'=>$this->data['User']
['username']);
             $a=$this->User->find($condition);
             if (!empty($a))
             echo $this->data['User']['username'].": Duplicate Entry";
        }
    }


I do not like repeating the same code again and again. I want to put
checkduplicate() in app_controller. Something like:

  function checkduplicate()
    {
        $this->autoRender=false;
        if (!empty(VALUE_OF_THE_FIELDS_TO_BE_VALIDATED)
 
{    $condition=array('FIELD_NAME'=>VALUE_OF_THE_FIELDS_TO_BE_VALIDATED);
             $a=$this->THE_MODEL_THIS_FIELD_BELONGS_TO-
>find($condition);
             if (!empty($a))
             echo VALUE_OF_THE_FIELDS_TO_BE_VALIDATED.": Duplicate
Entry";
        }
    }

However, how can I pass the field to the checkduplicate() in
app_controoller? The fields to be validated changes. In
checkduplicate(), I need to know which field it is and its value. How
can I do this?

Thanks,
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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