FormInterface.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. /**
  3. * @package Grav\Framework\Form
  4. *
  5. * @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
  6. * @license MIT License; see LICENSE file for details.
  7. */
  8. namespace Grav\Framework\Form\Interfaces;
  9. use Grav\Common\Data\Blueprint;
  10. use Grav\Common\Data\Data;
  11. use Grav\Framework\Interfaces\RenderInterface;
  12. use Psr\Http\Message\ServerRequestInterface;
  13. use Psr\Http\Message\UploadedFileInterface;
  14. /**
  15. * Interface FormInterface
  16. * @package Grav\Framework\Form
  17. */
  18. interface FormInterface extends RenderInterface, \Serializable
  19. {
  20. /**
  21. * Get HTML id="..." attribute.
  22. *
  23. * @return string
  24. */
  25. public function getId(): string;
  26. /**
  27. * Sets HTML id="" attribute.
  28. *
  29. * @param string $id
  30. */
  31. public function setId(string $id): void;
  32. /**
  33. * Get unique id for the current form instance. By default regenerated on every page reload.
  34. *
  35. * This id is used to load the saved form state, if available.
  36. *
  37. * @return string
  38. */
  39. public function getUniqueId(): string;
  40. /**
  41. * Sets unique form id.
  42. *
  43. * @param string $uniqueId
  44. */
  45. public function setUniqueId(string $uniqueId): void;
  46. /**
  47. * @return string
  48. */
  49. public function getName(): string;
  50. /**
  51. * Get form name.
  52. *
  53. * @return string
  54. */
  55. public function getFormName(): string;
  56. /**
  57. * Get nonce name.
  58. *
  59. * @return string
  60. */
  61. public function getNonceName(): string;
  62. /**
  63. * Get nonce action.
  64. *
  65. * @return string
  66. */
  67. public function getNonceAction(): string;
  68. /**
  69. * Get the nonce value for a form
  70. *
  71. * @return string
  72. */
  73. public function getNonce(): string;
  74. /**
  75. * Get task for the form if set in blueprints.
  76. *
  77. * @return string
  78. */
  79. public function getTask(): string;
  80. /**
  81. * Get form action (URL). If action is empty, it points to the current page.
  82. *
  83. * @return string
  84. */
  85. public function getAction(): string;
  86. /**
  87. * Get current data passed to the form.
  88. *
  89. * @return Data|object
  90. */
  91. public function getData();
  92. /**
  93. * Get files which were passed to the form.
  94. *
  95. * @return array|UploadedFileInterface[]
  96. */
  97. public function getFiles(): array;
  98. /**
  99. * Get a value from the form.
  100. *
  101. * Note: Used in form fields.
  102. *
  103. * @param string $name
  104. * @return mixed
  105. */
  106. public function getValue(string $name);
  107. /**
  108. * @param ServerRequestInterface $request
  109. * @return $this
  110. */
  111. public function handleRequest(ServerRequestInterface $request): FormInterface;
  112. /**
  113. * @param array $data
  114. * @param UploadedFileInterface[] $files
  115. * @return $this
  116. */
  117. public function submit(array $data, array $files = null): FormInterface;
  118. /**
  119. * @return bool
  120. */
  121. public function isValid(): bool;
  122. /**
  123. * @return string
  124. */
  125. public function getError(): ?string;
  126. /**
  127. * @return array
  128. */
  129. public function getErrors(): array;
  130. /**
  131. * @return bool
  132. */
  133. public function isSubmitted(): bool;
  134. /**
  135. * Reset form.
  136. */
  137. public function reset(): void;
  138. /**
  139. * Get form fields as an array.
  140. *
  141. * Note: Used in form fields.
  142. *
  143. * @return array
  144. */
  145. public function getFields(): array;
  146. /**
  147. * Get blueprint used in the form.
  148. *
  149. * @return Blueprint
  150. */
  151. public function getBlueprint(): Blueprint;
  152. }