Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cContentTypePifaForm
  • DefaultFormModule
  • DefaultFormProcessor
  • ExampleOptionsDatasource
  • MailedFormProcessor
  • Pifa
  • PifaAbstractFormModule
  • PifaAbstractFormProcessor
  • PifaAjaxHandler
  • PifaExporter
  • PifaExternalOptionsDatasourceInterface
  • PifaField
  • PifaFieldCollection
  • PifaForm
  • PifaFormCollection
  • PifaImporter
  • PifaLeftBottomPage
  • PifaRightBottomFormDataPage
  • PifaRightBottomFormExportPage
  • PifaRightBottomFormFieldsPage
  • PifaRightBottomFormImportPage
  • PifaRightBottomFormPage

Exceptions

  • PifaDatabaseException
  • PifaException
  • PifaIllegalStateException
  • PifaMailException
  • PifaNotImplementedException
  • PifaNotYetStoredException
  • PifaValidationException
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: /**
  4:  *
  5:  * @package Plugin
  6:  * @subpackage FormAssistant
  7:  * @author Marcus Gnaß <marcus.gnass@4fb.de>
  8:  * @copyright four for business AG
  9:  * @link http://www.4fb.de
 10:  */
 11: 
 12: /**
 13:  * This class is the default implementation for PIFA form modules.
 14:  * On a GET request it displays a form. On a POST request the posted data is
 15:  * processed. If an error occurs the form is displayed again only that now all
 16:  * valid data is displayed in the form and error messages (if defined) are
 17:  * displayed for all invalid form fields.
 18:  *
 19:  * @author Marcus Gnaß <marcus.gnass@4fb.de>
 20:  */
 21: class DefaultFormModule extends PifaAbstractFormModule {
 22: 
 23:     /**
 24:      * Handle GET request.
 25:      *
 26:      * @param array $values to be displayed in form
 27:      * @param array $errors to be displayed in form
 28:      * @throws Exception if form could not be loaded
 29:      * @see PifaAbstractFormModule::doGet()
 30:      */
 31:     protected function doGet(array $values = array(), array $errors = array()) {
 32: 
 33:         // set template to use
 34:         $this->setTemplateName($this->getSetting('pifaform_template_get'));
 35: 
 36:         // create and load form
 37:         $pifaForm = new PifaForm($this->getIdform());
 38: 
 39:         // catch error
 40:         if (true !== $pifaForm->isLoaded()) {
 41:             $msg = Pifa::i18n('FORM_LOAD_ERROR');
 42:             throw new PifaException($msg);
 43:         }
 44: 
 45:         // set values (keep default values if NULL!)
 46:         $pifaForm->setValues($values);
 47: 
 48:         // set errors
 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:         // assign rendered form
 61:         $this->getTpl()->assign('form', $pifaForm->toHtml(array(
 62:             'action' => $actionPath,
 63:             'headline' => $this->getSetting('pifaform_headline')
 64:         )));
 65:     }
 66: 
 67:     /**
 68:      * Handle POST request.
 69:      *
 70:      * @see PifaAbstractFormModule::doPost()
 71:      */
 72:     protected function doPost() {
 73: 
 74:         // set template to use
 75:         $this->setTemplateName($this->getSetting('pifaform_template_post'));
 76: 
 77:         try {
 78: 
 79:             // get name of processor class
 80:             $processorClass = $this->getSetting('pifaform_processor');
 81: 
 82:             // get name of file in which processor class could be found
 83:             $filename = Pifa::fromCamelCase($processorClass);
 84:             $filename = "extensions/class.pifa.$filename.php";
 85:             if (false === file_exists(Pifa::getPath() . $filename)) {
 86:                 $msg = Pifa::i18n('MISSING_PROCESSOR_FILE');
 87:                 $msg = sprintf($msg, $filename);
 88:                 throw new PifaException($msg);
 89:             }
 90:             plugin_include(Pifa::getName(), $filename);
 91:             if (false === class_exists($processorClass)) {
 92:                 $msg = Pifa::i18n('MISSING_PROCESSOR_CLASS');
 93:                 $msg = sprintf($msg, $processorClass);
 94:                 throw new PifaException($msg);
 95:             }
 96: 
 97:             // create processor instance
 98:             // pass module in order to access its settings
 99:             // processorClass is subclass of PifaAbstractFormProcessor
100:             $postProcessor = new $processorClass($this);
101:             $postProcessor->process();
102: 
103:             // assign reply to post template
104:             $this->getTpl()->assign('reply', array(
105:                 'headline' => mi18n("REPLY_HEADLINE"),
106:                 'text' => mi18n("REPLY_TEXT")
107:             ));
108:         } catch (PifaValidationException $e) {
109: 
110:             // display form with valid values again
111:             $this->doGet($postProcessor->getForm()->getValues(), $e->getErrors());
112: 
113:             // store validation state as (global) application so another module
114:             // can show a reply text but when validation is successfull
115:             cRegistry::setAppVar('pifaFormValidity', 'invalid');
116:         } catch (PifaException $e) {
117:             // display form with valid values again
118:             $this->doGet($postProcessor->getForm()->getValues());
119: 
120:             Pifa::displayException($e);
121:         } catch (Exception $e) {
122: 
123:             Pifa::logException($e);
124:             Pifa::displayException($e);
125:         }
126:     }
127: }
128: 
CMS CONTENIDO 4.10.0 API documentation generated by ApiGen 2.8.0