|
|
@ -13,10 +13,19 @@ abstract class Form |
|
|
|
{ |
|
|
|
|
|
|
|
const SUCCESS = 'success'; |
|
|
|
|
|
|
|
const ERROR = 'error'; |
|
|
|
|
|
|
|
/** |
|
|
|
* @var FormField[] |
|
|
|
*/ |
|
|
|
protected $fields = array(); |
|
|
|
protected $messages = array(self::SUCCESS => 'Form data valid', |
|
|
|
|
|
|
|
/** |
|
|
|
* @var array |
|
|
|
*/ |
|
|
|
protected $messages = array( |
|
|
|
self::SUCCESS => 'Form data valid', |
|
|
|
self::ERROR => 'Form data invalid'); |
|
|
|
|
|
|
|
protected $valid = true; |
|
|
@ -28,6 +37,7 @@ abstract class Form |
|
|
|
|
|
|
|
/** |
|
|
|
* @param string $name |
|
|
|
* @param bool|string $message |
|
|
|
* @return FormField |
|
|
|
*/ |
|
|
|
protected function addField($name, $message = false) |
|
|
@ -74,6 +84,9 @@ abstract class Form |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @return array |
|
|
|
*/ |
|
|
|
public function getValues() |
|
|
|
{ |
|
|
|
$values = array(); |
|
|
@ -85,6 +98,9 @@ abstract class Form |
|
|
|
return $values; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @return array |
|
|
|
*/ |
|
|
|
public function getSourceValues() |
|
|
|
{ |
|
|
|
$values = array(); |
|
|
@ -94,22 +110,36 @@ abstract class Form |
|
|
|
return $values; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @return string |
|
|
|
*/ |
|
|
|
public function getMessageType() |
|
|
|
{ |
|
|
|
return ($this->valid) ? self::SUCCESS : self::ERROR; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @return string |
|
|
|
*/ |
|
|
|
public function getMessage() |
|
|
|
{ |
|
|
|
return $this->messages[$this->getMessageType()]; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param string $message |
|
|
|
* @return Form |
|
|
|
*/ |
|
|
|
public function setSuccessMessage($message) |
|
|
|
{ |
|
|
|
$this->messages[self::SUCCESS] = (string) $message; |
|
|
|
return $this; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param string $message |
|
|
|
* @return Form |
|
|
|
*/ |
|
|
|
public function setErrorMessage($message) |
|
|
|
{ |
|
|
|
$this->messages[self::ERROR] = (string) $message; |
|
|
|