QuickForm whit controler Callback Trouble

From: Date: Thu, 14 Apr 2005 18:11:10 +0000
Subject: QuickForm whit controler Callback Trouble
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-18758@lists.php.net to get a copy of this message
Hello i´m coding a form and have trouble with a callback to check if a nick_name already exists on my db, the function doesn´t work anyone can help me? thanx class OrganizationForm extends HTML_QuickForm_Page { function buildForm() { $this->_formBuilt = true; $this->addElement('hidden', 'page', 'organizationform'); $this->addElement('text', 'name', _('name'), array('maxlength' => 50, 'size' => 30)); $this->addElement('text', 'nick_name', _('nick name'), array('maxlength' => 10, 'size' => 30)); $this->addElement('textarea', 'description', _('description'), array('cols' => 40, 'rows' => 6)); $required_fields = array( 'name','nick_name', 'description'); foreach ($required_fields as $field) { $element =& $this->getElement($field); $msg = $element->getLabel().': '. _('this field is mandatory'); $this->addRule($field, $msg, 'required', null, 'client'); } $this->registerRule('newnick', 'callback', 'isNewNickName', &$this); $this->addRule('nick_name',_('This nick name already is used, please change it.'), 'newnick'); $this->addElement('submit', $this->getButtonName('process'), _('send')); /** * Check if the nick name already exists. * @param string. nick_name */ } function isNewNickName($nick_name) { $organization = Organization::getOrganizationByNickName($nick_name); if ($organization) { return false; } return true; } } and the Organization: class Organization { /** * Returns all organization. * * @access public * @returns array. */ function getAll() { $query = 'SELECT * FROM organization'; $db = &Database::connect(); $db->setFetchMode(DB_FETCHMODE_ASSOC); $result = &$db->getAll($query); $db->disconnect(); if (PEAR::isError($result)) { Error::db($result); } if (!$result) { return; } return $result; } function getOrganizationByNickName($nick_name) { $query = 'SELECT * FROM organization WHERE nick_name = ?'; $db = &Database::connect(); $result = &$db->getRow($query, $nick_name); $db->disconnect(); if (PEAR::isError($result)) { Error::db($result); } if (!$result) { return; } return $result; } } -- -- Gabriel Sales de Oliveira

« previous php.pear.general (#18758) next »