Serverside Validation
authorAlex Kellner <alexander.kellner@in2code.de>
Tue, 4 Feb 2014 10:01:46 +0000 (11:01 +0100)
committerAlex Kellner <alexander.kellner@in2code.de>
Tue, 4 Feb 2014 10:01:46 +0000 (11:01 +0100)
Classes/Utility/EidDeRequiredFields.php [new file with mode: 0644]
Resources/Public/Js/PowermailCond.js
ext_localconf.php

diff --git a/Classes/Utility/EidDeRequiredFields.php b/Classes/Utility/EidDeRequiredFields.php
new file mode 100644 (file)
index 0000000..db441e1
--- /dev/null
@@ -0,0 +1,90 @@
+<?php
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2014 Alex Kellner <alexander.kellner@in2code.de>, in2code.de
+ *
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Store fields in session which should not be mandatory any more
+ *
+ * @author     Alex Kellner <alexander.kellner@in2code.de>, in2code.
+ * @package    TYPO3
+ * @subpackage Tx_PowermailCond_Utility_EidDeRequiredField
+ */
+class Tx_PowermailCond_Utility_EidDeRequiredFields {
+
+       /**
+        * Prefix Id
+        *
+        * @var string
+        */
+       public $prefixId = 'tx_powermailcond_pi1';
+
+       /**
+        * @var Tx_PowermailCond_Utility_Div
+        */
+       protected $div;
+
+       /**
+        * save field in session to be stored for non-mandatory fields
+        *
+        * @return int Field Uid which was disabled
+        */
+       public function main() {
+               $cObj = t3lib_div::makeInstance('tslib_cObj');
+               $piVars = t3lib_div::_GP($this->prefixId);
+               $formUid = intval($piVars['formUid']);
+               $fieldUids = explode(',', $piVars['fieldUids']);
+               $conditions = $this->div->getConditionsFromForm($this->piVars['formUid'], $cObj);
+
+               foreach ($fieldUids as $fieldUid) {
+                       // only if this field was defined as targetField in conditions
+                       if (array_key_exists($fieldUid, $conditions)) {
+                               // save single value in session
+                               $this->div->saveValueToSession('', $formUid, $fieldUid, 'deRequiredFields');
+                       }
+               }
+
+               return htmlspecialchars($piVars['fieldUids']);
+       }
+
+       /**
+        * Initialize eID
+        */
+       public function __construct($TYPO3_CONF_VARS) {
+               $userObj = tslib_eidtools::initFeUser();
+               $GLOBALS['TSFE'] = t3lib_div::makeInstance('tslib_fe', $TYPO3_CONF_VARS, 32, 0, TRUE);
+               $GLOBALS['TSFE']->connectToDB();
+               $GLOBALS['TSFE']->fe_user = $userObj;
+               $GLOBALS['TSFE']->id = t3lib_div::_GET('id');
+               $GLOBALS['TSFE']->determineId();
+               $GLOBALS['TSFE']->getCompressedTCarray();
+               $GLOBALS['TSFE']->initTemplate();
+               $GLOBALS['TSFE']->getConfigArray();
+               $GLOBALS['TSFE']->includeTCA();
+
+               $this->div = t3lib_div::makeInstance('Tx_PowermailCond_Utility_Div');
+       }
+}
+
+$eid = t3lib_div::makeInstance('Tx_PowermailCond_Utility_EidDeRequiredFields', $GLOBALS['TYPO3_CONF_VARS']);
+echo $eid->main();
\ No newline at end of file
index 29a8866..c9998d8 100644 (file)
@@ -155,10 +155,19 @@ function hideFieldset(string) {
        var params = string.split(':'); // filter / uid / values
        var values = params[2].split(';'); // value1 / value2 / value3
        $('.powermail_fieldset_' + params[1]).addClass('hide');
+       var fields = [];
        for (var k=0; k < values.length; k++) {
                clearValue('.powermail_fieldwrap_' + values[k] + ' .powermail_field');
-               deRequiredField(values[k]);
+               deRequiredField(values[k], true);
+               fields.push(values[k]);
        }
+
+       // save this field in session so it's no mandatory field any more
+       $.ajax({
+               url: '/index.php',
+               data: 'eID=' + 'powermailcond_deRequiredFields&tx_powermailcond_pi1[formUid]=' + getFormUid() + '&tx_powermailcond_pi1[fieldUids]=' + fields.join() + '&no_cache=1',
+               cache: false
+       });
 }
 
 /**
@@ -195,10 +204,11 @@ function showAll() {
 /**
  * Remove required class in Field
  *
- * @param      integer uid: uid of the element
- * @return     void
+ * @param integer uid of the element
+ * @param bool disableAjaxRequest
+ * @return void
  */
-function deRequiredField(uid) {
+function deRequiredField(uid, disableAjaxRequest) {
        var element = $('*[name="tx_powermail_pi1[field][' + uid +']"]');
        var classValue = element.attr('class');
        if (classValue && classValue.indexOf('required') !== -1) {
@@ -210,11 +220,13 @@ function deRequiredField(uid) {
                element.attr('required', false);
 
                // save this field in session so it's no mandatory field any more
-               $.ajax({
-                       url: '/index.php',
-                       data: 'eID=' + 'powermailcond_deRequiredField&tx_powermailcond_pi1[formUid]=' + getFormUid() + '&tx_powermailcond_pi1[fieldUid]=' + uid,
-                       cache: false
-               });
+               if (disableAjaxRequest == undefined && disableAjaxRequest === true) {
+                       $.ajax({
+                               url: '/index.php',
+                               data: 'eID=' + 'powermailcond_deRequiredField&tx_powermailcond_pi1[formUid]=' + getFormUid() + '&tx_powermailcond_pi1[fieldUid]=' + uid + '&no_cache=1',
+                               cache: false
+                       });
+               }
        }
 }
 
index 54a5dbc..46119c7 100644 (file)
@@ -34,6 +34,10 @@ $GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include']['powermailcond_clearSession'] =
 $GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include']['powermailcond_deRequiredField'] =
        'EXT:powermail_cond/Classes/Utility/EidDeRequiredField.php';
 
+// eID to save some fields in a separate session to select a field to be non-mandatory
+$GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include']['powermailcond_deRequiredFields'] =
+       'EXT:powermail_cond/Classes/Utility/EidDeRequiredFields.php';
+
 // eID to remove a field from session to select a field to be mandatory again
 $GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include']['powermailcond_requiredField'] =
        'EXT:powermail_cond/Classes/Utility/EidRequiredField.php';