HTML_QuickForm_Wizard
[ class tree: HTML_QuickForm_Wizard ] [ index: HTML_QuickForm_Wizard ] [ all elements ]

Source for file next.php

Documentation is available at next.php

  1. <?php
  2. /* vim: set number autoindent tabstop=2 shiftwidth=2 softtabstop=2: */
  3.  
  4. /**
  5. * Next action
  6. *
  7. * PHP versions 4 and 5
  8. *
  9. * LICENSE: This source file is subject to version 3.0 of the PHP license
  10. * that is available through the world-wide-web at the following URI:
  11. * http://www.php.net/license/3_0.txt. If you did not receive a copy of
  12. * the PHP License and are unable to obtain it through the web, please
  13. * send a note to license@php.net so we can mail you a copy immediately.
  14. *
  15. * @category HTML
  16. * @package HTML_QuickForm_Wizard
  17. * @author Fabio Ambrosanio <fabio@ambrosanio.com>
  18. * @license http://www.php.net/license/3_01.txt PHP
  19. * @version @package_version@
  20. *
  21. * $Id: next.php,v 1.3 2007/02/18 18:35:50 fabamb Exp $
  22. */
  23.  
  24. require_once 'HTML/QuickForm/Action/Next.php';
  25.  
  26. /**
  27. * This class implements "next" action that is to validate and save form's data and go to the next page
  28. *
  29. */
  30. class HTML_QuickForm_Wizard_next extends HTML_QuickForm_Action_Next
  31. {
  32. function perform(&$page, $actionName)
  33. {
  34. // save the form values and validation status to the session
  35. $page->isFormBuilt() or $page->buildForm();
  36. $pageName = $page->getAttribute('id');
  37. $data =& $page->controller->container();
  38. $data['values'][$pageName] = $page->exportValues();
  39. if (PEAR::isError($valid = $page->validate())) {
  40. return $valid;
  41. }
  42. $data['valid'][$pageName] = $valid;
  43.  
  44. // Modal form and page is invalid: don't go further
  45. if ($page->controller->isModal() && !$data['valid'][$pageName]) {
  46. return $page->handle('display');
  47. }
  48.  
  49. // check if this page is final
  50. if ($page->controller->isFinal($pageName)) {
  51. return $page->handle('process');
  52. }
  53.  
  54. // get next page from wizard
  55. if (null !== ($nextName = $page->controller->getNextName($pageName))) {
  56.  
  57. // sets valid all page between the actual and the next one
  58. $keys = $page->controller->getPageNames();
  59. $start = array_search($pageName, $keys);
  60. $stop = array_search($nextName, $keys);
  61. for($i = $start+1; $i < $stop; $i++) {
  62. $key = $keys[$i];
  63. if (!is_array($data['values'][$keys[$i]])) {
  64. $data['values'][$keys[$i]] = array();
  65. }
  66. $data['valid'][$key] = true;
  67. }
  68.  
  69. // jumps to the next page
  70. $next =& $page->controller->getPage($nextName);
  71. return $next->handle('jump');
  72. } else {
  73. // Consider this a 'finish' button, if there is no explicit one
  74. if($page->controller->isModal()) {
  75. if ($page->controller->isValid()) {
  76. return $page->handle('process');
  77. } else {
  78. // this should redirect to the first invalid page
  79. return $page->handle('jump');
  80. }
  81. } else {
  82. return $page->handle('display');
  83. }
  84. }
  85. }
  86. }
  87. ?>

Documentation generated on Thu, 19 Apr 2007 08:13:26 +0200 by phpDocumentor 1.3.0RC3