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 http://nettephp.com
- 12: *
- 18: */
- 26: /**
- 27: * Creates, validates and renders HTML forms.
- 28: *
- 32: *
- 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: *
- 54: */
- 56: {
- 57: /**#@+ operation name */
- 63: // button
- 66: // text
- 78: // file upload
- 82: // special case
- 84: /**#@-*/
- 86: /**#@+ method */
- 89: /**#@-*/
- 91: /** tracker ID */
- 94: /** protection token ID */
- 97: /** @var array of function(Form $sender); Occurs when the form is submitted and successfully validated */
- 100: /** @var array of function(Form $sender); Occurs when the form is submitted and not validated */
- 132: /**
- 133: * Form constructor.
- 134: */
- 136: {
- 143: }
- 145: }
- 149: /**
- 150: * This method will be called when the component (or component's parent)
- 151: * becomes attached to a monitored object. Do not call this method yourself.
- 154: */
- 156: {
- 159: }
- 160: }
- 164: /**
- 165: * Returns self.
- 167: */
- 169: {
- 171: }
- 175: /**
- 176: * Sets form's action.
- 179: */
- 181: {
- 183: }
- 187: /**
- 188: * Returns form's action.
- 190: */
- 192: {
- 194: }
- 198: /**
- 199: * Sets form's method.
- 202: */
- 204: {
- 206: }
- 210: /**
- 211: * Returns form's method.
- 213: */
- 215: {
- 217: }
- 221: /**
- 222: * Adds distinguishing mark.
- 225: */
- 227: {
- 229: }
- 233: /**
- 234: * Cross-Site Request Forgery (CSRF) form protection.
- 238: */
- 240: {
- 247: }
- 250: $this[self::PROTECTOR_ID]->addRule(':equal', empty($message) ? 'Security token did not match. Possible CSRF attack.' : $message, $token);
- 251: }
- 255: /**
- 256: * Adds fieldset group to the form.
- 260: */
- 262: {
- 269: }
- 275: }
- 276: }
- 280: /**
- 281: * Removes fieldset group from form.
- 284: */
- 286: {
- 296: }
- 300: }
- 303: }
- 307: /**
- 308: * Returns all defined groups.
- 310: */
- 312: {
- 314: }
- 318: /**
- 319: * Returns the specified group.
- 322: */
- 324: {
- 326: }
- 330: /**
- 331: * Set the encoding for the values.
- 334: */
- 336: {
- 339: throw new Exception("The PHP extension 'mbstring' is required for this encoding but is not loaded.");
- 340: }
- 341: }
- 345: /**
- 346: * Returns the encoding.
- 348: */
- 350: {
- 352: }
- 356: /********************* translator ****************d*g**/
- 360: /**
- 361: * Sets translate adapter.
- 364: */
- 366: {
- 368: }
- 372: /**
- 373: * Returns translate adapter.
- 375: */
- 377: {
- 379: }
- 383: /********************* submission ****************d*g**/
- 387: /**
- 388: * Tells if the form was submitted.
- 390: */
- 392: {
- 395: }
- 398: }
- 402: /**
- 403: * Sets the submittor control.
- 406: */
- 408: {
- 410: }
- 414: /**
- 415: * Detects form submission and loads HTTP values.
- 418: */
- 420: {
- 425: }
- 435: }
- 439: if (!isset($data[self::TRACKER_ID]) || $data[self::TRACKER_ID] !== $tracker->getValue()) return;
- 443: }
- 448: }
- 452: /**
- 453: * Fires submit/click events.
- 455: */
- 457: {
- 468: }
- 475: }
- 476: }
- 480: /********************* data exchange ****************d*g**/
- 484: /**
- 485: * Fill-in with default values.
- 489: */
- 491: {
- 494: }
- 495: }
- 499: /**
- 500: * Fill-in the form with HTTP data. Doesn't check if form was submitted.
- 503: */
- 505: {
- 512: }
- 515: if ($control instanceof ISubmitterControl && (!is_object($this->submittedBy) || $control->isSubmittedBy())) {
- 517: }
- 518: }
- 525: }
- 526: }
- 527: }
- 529: }
- 533: /**
- 534: * Was form populated by setDefaults() or processHttpRequest() yet?
- 536: */
- 538: {
- 540: }
- 544: /**
- 545: * Fill-in with values.
- 549: */
- 551: {
- 557: }
- 565: }
- 567: if ((is_array($sub->cursor) || $sub->cursor instanceof ArrayAccess) && array_key_exists($name, $sub->cursor)) {
- 572: }
- 573: }
- 580: }
- 581: }
- 582: }
- 584: }
- 588: /**
- 589: * Returns the values submitted by the form.
- 591: */
- 593: {
- 595: throw new InvalidStateException('Form was not populated yet. Call method isSubmitted() or setDefaults().');
- 596: }
- 605: }
- 606: if ($control instanceof IFormControl && !$control->isDisabled() && !($control instanceof ISubmitterControl)) {
- 608: }
- 612: }
- 613: }
- 616: }
- 620: /********************* validation ****************d*g**/
- 624: /**
- 625: * Is form valid?
- 627: */
- 629: {
- 632: }
- 634: }
- 638: /**
- 639: * Performs the server side validation.
- 641: */
- 643: {
- 645: throw new InvalidStateException('Form was not populated yet. Call method isSubmitted() or setDefaults().');
- 646: }
- 654: }
- 655: }
- 656: }
- 660: /**
- 661: * Adds error message to the list.
- 664: */
- 666: {
- 670: }
- 671: }
- 675: /**
- 676: * Returns validation errors.
- 678: */
- 680: {
- 682: }
- 686: /**
- 688: */
- 690: {
- 692: }
- 696: /**
- 698: */
- 700: {
- 703: }
- 707: /********************* rendering ****************d*g**/
- 711: /**
- 712: * Returns form's HTML element template.
- 714: */
- 716: {
- 718: }
- 722: /**
- 723: * Sets form renderer.
- 726: */
- 728: {
- 730: }
- 734: /**
- 735: * Returns form renderer.
- 737: */
- 739: {
- 742: }
- 744: }
- 748: /**
- 749: * Renders form.
- 751: */
- 753: {
- 762: }
- 763: }
- 767: /**
- 768: * Renders form to string.
- 771: */
- 773: {
- 779: }
- 787: }
- 788: }
- 789: }
- 793: /********************* backend ****************d*g**/
- 797: /**
- 799: */
- 801: {
- 803: }
- 807: /**
- 809: */
- 811: {
- 813: }
- 815: }