Display.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4.0 |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.0 of the PHP license, |
  9. // | that is bundled with this package in the file LICENSE, and is |
  10. // | available at through the world-wide-web at |
  11. // | http://www.php.net/license/2_02.txt. |
  12. // | If you did not receive a copy of the PHP license and are unable to |
  13. // | obtain it through the world-wide-web, please send a note to |
  14. // | license@php.net so we can mail you a copy immediately. |
  15. // +----------------------------------------------------------------------+
  16. // | Author: Alexey Borzov <avb@php.net> |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: Display.php 6184 2005-09-07 10:08:17Z bmol $
  20. require_once 'HTML/QuickForm/Action.php';
  21. /**
  22. * This action handles the output of the form.
  23. *
  24. * If you want to customize the form display, subclass this class and
  25. * override the _renderForm() method, you don't need to change the perform()
  26. * method itself.
  27. *
  28. * @author Alexey Borzov <avb@php.net>
  29. * @package HTML_QuickForm_Controller
  30. * @version $Revision: 6184 $
  31. */
  32. class HTML_QuickForm_Action_Display extends HTML_QuickForm_Action
  33. {
  34. function perform(&$page, $actionName)
  35. {
  36. $pageName = $page->getAttribute('id');
  37. // If the original action was 'display' and we have values in container then we load them
  38. // BTW, if the page was invalid, we should later call validate() to get the errors
  39. list(, $oldName) = $page->controller->getActionName();
  40. if ('display' == $oldName) {
  41. // If the controller is "modal" we should not allow direct access to a page
  42. // unless all previous pages are valid (see also bug #2323)
  43. if ($page->controller->isModal() && !$page->controller->isValid($page->getAttribute('id'))) {
  44. $target =& $page->controller->getPage($page->controller->findInvalid());
  45. return $target->handle('jump');
  46. }
  47. $data =& $page->controller->container();
  48. if (!empty($data['values'][$pageName])) {
  49. $page->loadValues($data['values'][$pageName]);
  50. $validate = false === $data['valid'][$pageName];
  51. }
  52. }
  53. // set "common" defaults and constants
  54. $page->controller->applyDefaults($pageName);
  55. $page->isFormBuilt() or $page->buildForm();
  56. // if we had errors we should show them again
  57. if (isset($validate) && $validate) {
  58. $page->validate();
  59. }
  60. return $this->_renderForm($page);
  61. }
  62. /**
  63. * Actually outputs the form.
  64. *
  65. * If you want to customize the form's appearance (you most certainly will),
  66. * then you should override this method. There is no need to override perform()
  67. *
  68. * @access public
  69. * @param object HTML_QuickForm_Page the page being processed
  70. */
  71. function _renderForm(&$page)
  72. {
  73. $page->display();
  74. }
  75. }
  76. ?>