1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace Nette\Application\UI;
13:
14: use Nette;
15:
16:
17:
18: 19: 20: 21: 22: 23: 24:
25: class Form extends Nette\Forms\Form implements ISignalReceiver
26: {
27:
28: 29: 30:
31: public function __construct(Nette\ComponentModel\IContainer $parent = NULL, $name = NULL)
32: {
33: parent::__construct();
34: $this->monitor('Nette\Application\UI\Presenter');
35: if ($parent !== NULL) {
36: $parent->addComponent($this, $name);
37: }
38: }
39:
40:
41:
42: 43: 44: 45: 46:
47: public function getPresenter($need = TRUE)
48: {
49: return $this->lookup('Nette\Application\UI\Presenter', $need);
50: }
51:
52:
53:
54: 55: 56: 57: 58: 59:
60: protected function attached($presenter)
61: {
62: if ($presenter instanceof Presenter) {
63: $name = $this->lookupPath('Nette\Application\UI\Presenter');
64:
65: if (!isset($this->getElementPrototype()->id)) {
66: $this->getElementPrototype()->id = 'frm-' . $name;
67: }
68:
69: $this->setAction(new Link(
70: $presenter,
71: $name . self::NAME_SEPARATOR . 'submit!',
72: array()
73: ));
74:
75:
76: if ($this->isSubmitted()) {
77: foreach ($this->getControls() as $control) {
78: $control->loadHttpData();
79: }
80: }
81: }
82: parent::attached($presenter);
83: }
84:
85:
86:
87: 88: 89: 90:
91: public function isAnchored()
92: {
93: return (bool) $this->getPresenter(FALSE);
94: }
95:
96:
97:
98: 99: 100: 101:
102: protected function receiveHttpData()
103: {
104: $presenter = $this->getPresenter();
105: if (!$presenter->isSignalReceiver($this, 'submit')) {
106: return;
107: }
108:
109: $isPost = $this->getMethod() === self::POST;
110: $request = $presenter->getRequest();
111: if ($request->isMethod('forward') || $request->isMethod('post') !== $isPost) {
112: return;
113: }
114:
115: if ($isPost) {
116: return Nette\Utils\Arrays::mergeTree($request->getPost(), $request->getFiles());
117: } else {
118: return $request->getParameters();
119: }
120: }
121:
122:
123:
124:
125:
126:
127:
128: 129: 130: 131: 132:
133: public function signalReceived($signal)
134: {
135: if ($signal === 'submit') {
136: if (!$this->getPresenter()->getRequest()->hasFlag(Nette\Application\Request::RESTORED)) {
137: $this->fireEvents();
138: }
139: } else {
140: $class = get_class($this);
141: throw new BadSignalException("Missing handler for signal '$signal' in $class.");
142: }
143: }
144:
145: }
146: