I have written one function in User Mapper class userExist($username)
which return true
if same username does not exist in my database table. Now I want to use this function in the Add_User_Form class which extends Zend_Form.
I want to use:
$username = $this->createElement('text','username');
$username->setLabel('Username:')
->addValidator('Callback', true, array('callback'=>userExist???));
Can I use mapper class userExist($username)
function as callback function?
Please let me know if I am doing something wrong with my implementation. I just want to show error messages if a user is already registered and prevent form submission.
Thank you.
Instead of using a callback validator, you can use a standard validator:
Db_NoRecordExists allows you to check whether a record exists in a specific table of your database.
If a user want to edit his profile, you might want to check if a record exists except itself. Then you should use the same validator as follow:
In these example,
users
is the name of your database table.username
is your column name and$username
the username you want to exclude.Bit late but this may be a possible answer to your question.
Date Element example:
I created a date element with a custom Callback validator that calls a method in the same form class.
If you have your own class with custom validators in it then you can do this:
In the same form class I created the custom validation method:
Or if you are using your own class:
If the methods aren't
public
the Callback will not find them.