<?php
/**
 * class account_form
 *
 * Description for class account_form
 *
 * @author:
*/
namespace area\presenter\form;

use core\form;
use core\user;

class account_form extends form {
	public $name = "";

	public function init() {
		$this->addElement("name", array("required", "max_length(50)"));
	}

	public function valid() {
		if(!$this->send) {
			return false;
		}

		$valid = true;

		$this->name = $this->getElement("name")->getValue();
		if(empty($this->name)) {
			$this->elements["name"]->setError("Pole wymagane");
			$valid = false;
		} elseif(strlen($this->name) > 50) {
			$this->elements["name"]->setError("Maksymalna długość 80 znaków");
			$valid = false;
		}
		
		return $valid;
	}

	public function save() {
		return user::updateName($this->name);
	}
}
?>