Source for file Form.php
Documentation is available at Form.php
- 1: <?php
- 3: /**
- 4: * Nette Framework
- 5: *
- 6: * Copyright (c) 2004, 2009 David Grudl (http://davidgrudl.com)
- 7: *
- 8: * This source file is subject to the "Nette license" that is bundled
- 9: * with this package in the file license.txt.
- 10: *
- 11: * For more information please see https://nette.org
- 12: *
- 19: */
- 27: /**
- 28: * Creates, validates and renders HTML forms.
- 29: *
- 34: * @example forms/manual-rendering.php Manual form rendering and separated form and rules definition
- 39: * @example forms/CSRF-protection.php How to use Cross-Site Request Forgery (CSRF) form protection
- 41: */
- 43: {
- 44: /**#@+ operation name */
- 50: // button
- 53: // text
- 65: // file upload
- 69: // special case
- 71: /**#@-*/
- 73: /** tracker ID */
- 76: /** protection token ID */
- 79: /** @var array of event handlers; Occurs when the form is submitted and successfully validated; function(Form $sender) */
- 82: /** @var array of event handlers; Occurs when the form is submitted and not validated; function(Form $sender) */
- 114: /**
- 115: * Form constructor.
- 116: */
- 118: {
- 124: }
- 128: /**
- 129: * This method will be called when the component (or component's parent)
- 130: * becomes attached to a monitored object. Do not call this method yourself.
- 133: */
- 135: {
- 138: }
- 139: }
- 143: /**
- 144: * Returns self.
- 146: */
- 148: {
- 150: }
- 154: /**
- 155: * Sets form's action.
- 158: */
- 160: {
- 162: }
- 166: /**
- 167: * Returns form's action.
- 169: */
- 171: {
- 173: }
- 177: /**
- 178: * Sets form's method.
- 181: */
- 183: {
- 185: }
- 189: /**
- 190: * Returns form's method.
- 192: */
- 194: {
- 196: }
- 200: /**
- 201: * Adds distinguishing mark.
- 204: */
- 206: {
- 208: }
- 212: /**
- 213: * Cross-Site Request Forgery (CSRF) form protection.
- 217: */
- 219: {
- 226: }
- 229: $this[self::PROTECTOR_ID]->addRule(':equal', empty($message) ? 'Security token did not match. Possible CSRF attack.' : $message, $token);
- 230: }
- 234: /**
- 235: * Adds fieldset group to the form.
- 239: */
- 241: {
- 248: }
- 254: }
- 255: }
- 259: /**
- 260: * Returns all defined groups.
- 262: */
- 264: {
- 266: }
- 270: /**
- 271: * Returns the specified group.
- 274: */
- 276: {
- 278: }
- 282: /**
- 283: * Set the encoding for the values.
- 286: */
- 288: {
- 291: throw new Exception("The PHP extension 'mbstring' is required for this encoding but is not loaded.");
- 292: }
- 293: }
- 297: /**
- 298: * Returns the encoding.
- 300: */
- 302: {
- 304: }
- 308: /********************* translator ****************d*g**/
- 312: /**
- 313: * Sets translate adapter.
- 316: */
- 318: {
- 320: }
- 324: /**
- 325: * Returns translate adapter.
- 327: */
- 329: {
- 331: }
- 335: /********************* submission ****************d*g**/
- 339: /**
- 340: * Tells if the form was submitted.
- 342: */
- 344: {
- 347: }
- 350: }
- 354: /**
- 355: * Sets the submittor control.
- 358: */
- 360: {
- 362: }
- 366: /**
- 367: * Detects form submission and loads HTTP values.
- 370: */
- 372: {
- 377: }
- 387: }
- 391: if (!isset($data[self::TRACKER_ID]) || $data[self::TRACKER_ID] !== $tracker->getValue()) return;
- 395: }
- 400: }
- 404: /**
- 405: * Fires submit/click events.
- 407: */
- 409: {
- 420: }
- 427: }
- 428: }
- 432: /********************* data exchange ****************d*g**/
- 436: /**
- 437: * Fill-in with default values.
- 441: */
- 443: {
- 446: }
- 447: }
- 451: /**
- 452: * Fill-in the form with HTTP data. Doesn't check if form was submitted.
- 455: */
- 457: {
- 464: }
- 467: if ($control instanceof ISubmitterControl && (!is_object($this->submittedBy) || $control->isSubmittedBy())) {
- 469: }
- 470: }
- 477: }
- 478: }
- 479: }
- 481: }
- 485: /**
- 486: * Was form populated by setDefaults() or processHttpRequest() yet?
- 488: */
- 490: {
- 492: }
- 496: /**
- 497: * Fill-in with values.
- 501: */
- 503: {
- 509: }
- 517: }
- 519: if ((is_array($sub->cursor) || $sub->cursor instanceof ArrayAccess) && array_key_exists($name, $sub->cursor)) {
- 524: }
- 525: }
- 532: }
- 533: }
- 534: }
- 536: }
- 540: /**
- 541: * Returns the values submitted by the form.
- 543: */
- 545: {
- 547: throw new InvalidStateException('Form was not populated yet. Call method isSubmitted() or setDefaults().');
- 548: }
- 557: }
- 558: if ($control instanceof IFormControl && !$control->isDisabled() && !($control instanceof ISubmitterControl)) {
- 560: }
- 564: }
- 565: }
- 568: }
- 572: /********************* validation ****************d*g**/
- 576: /**
- 577: * Is form valid?
- 579: */
- 581: {
- 584: }
- 586: }
- 590: /**
- 591: * Performs the server side validation.
- 593: */
- 595: {
- 597: throw new InvalidStateException('Form was not populated yet. Call method isSubmitted() or setDefaults().');
- 598: }
- 606: }
- 607: }
- 608: }
- 612: /**
- 613: * Adds error message to the list.
- 616: */
- 618: {
- 622: }
- 623: }
- 627: /**
- 628: * Returns validation errors.
- 630: */
- 632: {
- 634: }
- 638: /**
- 640: */
- 642: {
- 644: }
- 648: /**
- 650: */
- 652: {
- 655: }
- 659: /********************* rendering ****************d*g**/
- 663: /**
- 664: * Returns form's HTML element template.
- 666: */
- 668: {
- 670: }
- 674: /**
- 675: * Sets form renderer.
- 678: */
- 680: {
- 682: }
- 686: /**
- 687: * Returns form renderer.
- 689: */
- 691: {
- 694: }
- 696: }
- 700: /**
- 701: * Renders form.
- 703: */
- 705: {
- 714: }
- 715: }
- 719: /**
- 720: * Renders form to string.
- 723: */
- 725: {
- 731: }
- 739: }
- 740: }
- 741: }
- 745: /********************* backend ****************d*g**/
- 749: /**
- 751: */
- 753: {
- 755: }
- 759: /**
- 761: */
- 763: {
- 765: }
- 767: }