1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12: 13: 14: 15: 16: 17: 18: 19: 20:
21: class DefaultFormModule extends PifaAbstractFormModule {
22:
23: 24: 25: 26: 27: 28: 29: 30:
31: protected function doGet(array $values = array(), array $errors = array()) {
32:
33:
34: $this->setTemplateName($this->getSetting('pifaform_template_get'));
35:
36:
37: $pifaForm = new PifaForm($this->getIdform());
38:
39:
40: if (true !== $pifaForm->isLoaded()) {
41: $msg = Pifa::i18n('FORM_LOAD_ERROR');
42: throw new PifaException($msg);
43: }
44:
45:
46: $pifaForm->setValues($values);
47:
48:
49: $pifaForm->setErrors($errors);
50:
51: $actionPath = cUri::getInstance()->build(array(
52: 'idart' => cRegistry::getArticleId(),
53: 'lang' => cRegistry::getLanguageId()
54: ), true);
55:
56: if (Pifa::isHttps()) {
57: $actionPath = str_replace('http://', 'https://', $actionPath);
58: }
59:
60:
61: $this->getTpl()->assign('form', $pifaForm->toHtml(array(
62: 'action' => $actionPath,
63: 'headline' => $this->getSetting('pifaform_headline')
64: )));
65: }
66:
67: 68: 69: 70: 71: 72:
73: protected function doPost() {
74:
75:
76: $this->setTemplateName($this->getSetting('pifaform_template_post'));
77:
78: try {
79:
80:
81: $processorClass = $this->getSetting('pifaform_processor');
82:
83:
84: $filename = Pifa::fromCamelCase($processorClass);
85: $filename = "extensions/class.pifa.$filename.php";
86: if (false === file_exists(Pifa::getPath() . $filename)) {
87: $msg = Pifa::i18n('MISSING_PROCESSOR_FILE');
88: $msg = sprintf($msg, $filename);
89: throw new PifaException($msg);
90: }
91: plugin_include(Pifa::getName(), $filename);
92: if (false === class_exists($processorClass)) {
93: $msg = Pifa::i18n('MISSING_PROCESSOR_CLASS');
94: $msg = sprintf($msg, $processorClass);
95: throw new PifaException($msg);
96: }
97:
98:
99:
100:
101: $postProcessor = new $processorClass($this);
102: $postProcessor->process();
103:
104:
105: $this->getTpl()->assign('reply', array(
106: 'headline' => mi18n("REPLY_HEADLINE"),
107: 'text' => mi18n("REPLY_TEXT")
108: ));
109: } catch (PifaValidationException $e) {
110:
111:
112: $this->doGet($postProcessor->getForm()->getValues(), $e->getErrors());
113:
114:
115:
116: cRegistry::setAppVar('pifaFormValidity', 'invalid');
117: } catch (PifaException $e) {
118:
119: $this->doGet($postProcessor->getForm()->getValues());
120:
121: Pifa::displayException($e);
122: } catch (Exception $e) {
123:
124: Pifa::logException($e);
125: Pifa::displayException($e);
126: }
127: }
128: }
129: