Location: PHPKode > projects > AModules3 > amodules-3.0.1/mini-apps/03-DocAssistant/Form/RegistrationData.php
<?php
/*
 * Created on 09.03.2006 by *Camper*
 */
class Form_RegistrationData extends Form{
	private $is_update = false;
	public $id;
	
	function init(){
		parent::init();
		$this
			->addField('line', 'name', 'Your login')
			->addField('password', 'password', 'Your password')
			->addField('password', 'password2', 'Confirm password')->setNoSave()
			->addField('line', 'first_name', 'First name')->validateNotNull()
			->addField('line', 'last_name', 'Last Name')->validateNotNull()
			->addField('line', 'email', 'E-Mail')->validateNotNull()
			
			->addSubmit('Submit')
			
			->setSource('user')
			->addCondition('id', $this->api->getUserId());
		;
		if($this->isUpdate())$this->set('password2', $this->get('password'));
		$this->elements['password']->addHook('validate', array($this, 'validatePassword'));
		$this->elements['password2']->addHook('validate', array($this, 'validatePassword2'));
	}
	function loadData(){
		parent::loadData();
		$this->set('password2', $this->get('password'));
	}
		
	function validateLogin(){
		if($this->isUpdate())return true;
		
		if(trim($this->get('name')) == ''){
			$this->elements['name']->displayFieldError('Username should NOT be blank!');
			return false;
		}
		$nc = $this->api->db->getOne("select count(*) from user where name = '".
			$this->get('name')."'");
		if($nc > 0)$this->elements['name']->displayFieldError('User with this name ' .
				'already exists. Please choose another one.');
	}
	function validatePassword(){
		//TODO validate password
	}
	function validatePassword2(){
	}
	function isUpdate(){
		return $this->is_update;
	}
	function submitted(){
		if(!parent::submitted())return true;
		//crypting password
		if(!$this->isUpdate())$this->set('password', sha1($this->get('password')));
		else{
			if($this->get('password') != $this->api->recall('oldpassword', ''))
				$this->set('password', sha1($this->get('password')));
		}
		if(!$adv_id = $this->update())throw new BaseException("Cannot save record");
		$this->api->redirect('Index');
	}
}

?>
Return current item: AModules3