You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.1 KiB

10 years ago
10 years ago
10 years ago
  1. <?php namespace Majestic\Form;
  2. /**
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage Form
  7. * @since 2010-04-25
  8. */
  9. class FormViewHelper extends ViewHelper
  10. {
  11. protected $data = null;
  12. public function form($form = null)
  13. {
  14. if ($this->data === null) {
  15. if ($form == null) {
  16. throw new \Majestic\ExceptionInitializationException('Form name required for helper init');
  17. }
  18. $this->data = \Majestic\Session\Session::get($form, array());
  19. \Majestic\Session\Session::del($form);
  20. }
  21. return $this;
  22. }
  23. public function value($field, $default = '')
  24. {
  25. if (isset($this->data['values'][$field])) {
  26. return $this->view->escape($this->data['values'][$field]);
  27. }
  28. return $this->view->escape($default);
  29. }
  30. public function message($field)
  31. {
  32. if (isset($this->data['messages'][$field])) {
  33. return '<span class="error">' . $this->view->escape($this->data['messages'][$field]) . '</span>';
  34. }
  35. return '';
  36. }
  37. }