Source for file SubmitButton.php

Documentation is available at SubmitButton.php

  1. 1: <?php
  2. 2:  
  3. 3: /**
  4. 4:  * Nette Framework
  5. 5:  *
  6. 6:  * Copyright (c) 2004, 2009 David Grudl (http://davidgrudl.com)
  7. 7:  *
  8. 8:  * This source file is subject to the "Nette license" that is bundled
  9. 9:  * with this package in the file license.txt.
  10. 10:  *
  11. 11:  * For more information please see https://nette.org
  12. 12:  *
  13. 13:  * @copyright  Copyright (c) 2004, 2009 David Grudl
  14. 14:  * @license    https://nette.org/license  Nette license
  15. 15:  * @link       https://nette.org
  16. 16:  * @category   Nette
  17. 17:  * @package    Nette\Forms
  18. 18:  * @version    $Id$
  19. 19:  */
  20. 20:  
  21. 21:  
  22. 22:  
  23. 23: require_once dirname(__FILE__'/../../Forms/Controls/Button.php';
  24. 24:  
  25. 25: require_once dirname(__FILE__'/../../Forms/ISubmitterControl.php';
  26. 26:  
  27. 27:  
  28. 28:  
  29. 29: /**
  30. 30:  * Submittable button control.
  31. 31:  *
  32. 32:  * @author     David Grudl
  33. 33:  * @copyright  Copyright (c) 2004, 2009 David Grudl
  34. 34:  * @package    Nette\Forms
  35. 35:  */
  36. 36: class SubmitButton extends Button implements ISubmitterControl
  37. 37: {
  38. 38:     /** @var array of event handlers; Occurs when the button is clicked and form is successfully validated; function(SubmitButton $sender) */
  39. 39:     public $onClick;
  40. 40:  
  41. 41:     /** @var array of event handlers; Occurs when the button is clicked and form is not validated; function(SubmitButton $sender) */
  42. 42:     public $onInvalidClick;
  43. 43:  
  44. 44:     /** @var mixed */
  45. 45:     private $validationScope TRUE;
  46. 46:  
  47. 47:  
  48. 48:  
  49. 49:     /**
  50. 50:      * @param  string  caption
  51. 51:      */
  52. 52:     public function __construct($caption)
  53. 53:     {
  54. 54:         parent::__construct($caption);
  55. 55:         $this->control->type 'submit';
  56. 56:     }
  57. 57:  
  58. 58:  
  59. 59:  
  60. 60:     /**
  61. 61:      * Tells if the form was submitted by this button.
  62. 62:      * @return bool 
  63. 63:      */
  64. 64:     public function isSubmittedBy()
  65. 65:     {
  66. 66:         return (bool) $this->value;
  67. 67:     }
  68. 68:  
  69. 69:  
  70. 70:  
  71. 71:     /**
  72. 72:      * Sets the validation scope. Clicking the button validates only the controls within the specified scope.
  73. 73:      * @param  mixed 
  74. 74:      * @return SubmitButton  provides a fluent interface
  75. 75:      */
  76. 76:     public function setValidationScope($scope)
  77. 77:     {
  78. 78:         // TODO: implement groups
  79. 79:         $this->validationScope = (bool) $scope;
  80. 80:         return $this;
  81. 81:     }
  82. 82:  
  83. 83:  
  84. 84:  
  85. 85:     /**
  86. 86:      * Gets the validation scope.
  87. 87:      * @return mixed 
  88. 88:      */
  89. 89:     final public function getValidationScope()
  90. 90:     {
  91. 91:         return $this->validationScope;
  92. 92:     }
  93. 93:  
  94. 94:  
  95. 95:  
  96. 96:     /**
  97. 97:      * Fires click event.
  98. 98:      * @return void 
  99. 99:      */
  100. 100:     public function click()
  101. 101:     {
  102. 102:         $this->onClick($this);
  103. 103:     }
  104. 104:  
  105. 105:  
  106. 106:  
  107. 107:     /**
  108. 108:      * Submitted validator: has been button pressed?
  109. 109:      * @param  ISubmitterControl 
  110. 110:      * @return bool 
  111. 111:      */
  112. 112:     public static function validateSubmitted(ISubmitterControl $control)
  113. 113:     {
  114. 114:         return $control->isSubmittedBy();
  115. 115:     }
  116. 116: