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
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • 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
  • SolrRightBottomPage

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:         )));
 64:     }
 65: 
 66:     /**
 67:      * Handle POST request.
 68:      *
 69:      * @see PifaAbstractFormModule::doPost()
 70:      */
 71:     protected function doPost() {
 72: 
 73:         // set template to use
 74:         $this->setTemplateName($this->getSetting('pifaform_template_post'));
 75: 
 76:         try {
 77: 
 78:             // get name of processor class
 79:             $processorClass = $this->getSetting('pifaform_processor');
 80: 
 81:             // get name of file in which processor class could be found
 82:             $filename = Pifa::fromCamelCase($processorClass);
 83:             $filename = "extensions/class.pifa.$filename.php";
 84:             if (false === file_exists(Pifa::getPath() . $filename)) {
 85:                 $msg = Pifa::i18n('MISSING_PROCESSOR_FILE');
 86:                 $msg = sprintf($msg, $filename);
 87:                 throw new PifaException($msg);
 88:             }
 89:             plugin_include(Pifa::getName(), $filename);
 90:             if (false === class_exists($processorClass)) {
 91:                 $msg = Pifa::i18n('MISSING_PROCESSOR_CLASS');
 92:                 $msg = sprintf($msg, $processorClass);
 93:                 throw new PifaException($msg);
 94:             }
 95: 
 96:             // create processor instance
 97:             // pass module in order to access its settings
 98:             // processorClass is subclass of PifaAbstractFormProcessor
 99:             $postProcessor = new $processorClass($this);
100:             $postProcessor->process();
101: 
102:             // assign reply to post template
103:             $this->getTpl()->assign('reply', array(
104:                 'headline' => mi18n("REPLY_HEADLINE"),
105:                 'text' => mi18n("REPLY_TEXT")
106:             ));
107:         } catch (PifaValidationException $e) {
108: 
109:             // display form with valid values again
110:             $this->doGet($postProcessor->getForm()->getValues(), $e->getErrors());
111: 
112:             // store validation state as (global) application so another module
113:             // can show a reply text but when validation is successfull
114:             cRegistry::setAppVar('pifaFormValidity', 'invalid');
115:         } catch (PifaException $e) {
116:             // display form with valid values again
117:             $this->doGet($postProcessor->getForm()->getValues());
118: 
119:             Pifa::displayException($e);
120:         } catch (Exception $e) {
121: 
122:             Pifa::logException($e);
123:             Pifa::displayException($e);
124:         }
125:     }
126: }
127: 
CMS CONTENIDO 4.9.11 API documentation generated by ApiGen 2.8.0