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