* Added support for JavaScript regular expression evaluation in FORM cObject. Means...
authorKasper Skårhøj <kasper@typo3.org>
Mon, 19 Apr 2004 15:25:54 +0000 (15:25 +0000)
committerKasper Skårhøj <kasper@typo3.org>
Mon, 19 Apr 2004 15:25:54 +0000 (15:25 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@206 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/jsfunc.validateform.js
typo3/sysext/cms/tslib/class.tslib_content.php
typo3/sysext/lang/locallang_wizards.php
typo3/wizard_forms.php

index c23e7ff..b0e5367 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2004-04-19  Kasper Skårhøj,,,  <kasper@typo3.com>
 
+       * Added support for JavaScript regular expression evaluation in FORM cObject. Means that fields in formmails can now be checked for a pattern and not only for "required".
+
+2004-04-19  Kasper Skårhøj,,,  <kasper@typo3.com>
+
        * Added possibility to copy database/file elements attached to records; You can now click the icon of these elements in the editing forms and get a (limited) context menu for these elements.
        * Fixed some other bugs around.
 
index d85225d..45cece5 100755 (executable)
 ***************************************************************/
 
 
-function validateForm(theFormname,theFieldlist,goodMess,badMess)       {
+function validateForm(theFormname,theFieldlist,goodMess,badMess,emailMess)     {
        if (document[theFormname] && theFieldlist)      {
                var index=1;
                var theField = split(theFieldlist, ",", index);
                var msg="";
+               var theEreg = '';
+               var theEregMsg = '';
+               var specialMode = '';
+
                while (theField) {
+                       theEreg = '';
+                       specialMode = '';
+
+                               // Check special modes:
+                       if (theField == '_EREG')        {       // EREG mode: _EREG,[error msg],[JS ereg],[fieldname],[field Label]
+                               specialMode = theField;
+
+                               index++;
+                               theEregMsg = unescape(split(theFieldlist, ",", index));
+                               index++;
+                               theEreg = unescape(split(theFieldlist, ",", index));
+                       } else if (theField == '_EMAIL')        {
+                               specialMode = theField;
+                       }
+
+                               // Get real field name if special mode has been set:
+                       if (specialMode)        {
+                               index++;
+                               theField = split(theFieldlist, ",", index);
+                       }
+
                        index++;
                        theLabel = unescape(split(theFieldlist, ",", index));
                        theField = unescape(theField);
@@ -69,8 +94,25 @@ function validateForm(theFormname,theFieldlist,goodMess,badMess)     {
                                        default:
                                                value=1;
                                }
-                               if (!value)     {
-                                       msg+="\n"+theLabel;
+
+                               switch(specialMode)     {
+                                       case "_EMAIL":
+                                               var theRegEx_notValid = new RegExp("(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)", "gi");
+                                               var theRegEx_isValid = new RegExp("^.+\@[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})$","");
+                                               if (!theRegEx_isValid.test(value))      {       // This part was supposed to be a part of the condition: " || theRegEx_notValid.test(value)" - but I couldn't make it work (Mozilla Firefox, linux) - Anyone knows why?
+                                                       msg+="\n"+theLabel+' ('+(emailMess ? unescape(emailMess) : 'Email address not valid!')+')';
+                                               }
+                                       break;
+                                       case "_EREG":
+                                               var theRegEx_isValid = new RegExp(theEreg,"");
+                                               if (!theRegEx_isValid.test(value))      {
+                                                       msg+="\n"+theLabel+' ('+theEregMsg+')';
+                                               }
+                                       break;
+                                       default:
+                                               if (!value)     {
+                                                       msg+="\n"+theLabel;
+                                               }
                                }
                        }
                        index++;
index d9ba0cf..7202fdc 100755 (executable)
@@ -1505,27 +1505,30 @@ class tslib_cObj {
                                                        }
                                                        $temp[2] = implode(',',$temp_accum);
                                                }
+                                               list($temp[3])= explode('|',$dAA['specialEval.'] ? $this->stdWrap($dAA['specialEval'],$dAA['specialEval.']) : $dAA['specialEval']);
+
                                                        // adding the form entry to the dataArray
                                                $dataArr[] = implode('|',$temp);
                                        }
                                }
                        }
                }
-               $attachmentCounter='';
-               $hiddenfields='';
-               $fieldlist=Array();
+
+               $attachmentCounter = '';
+               $hiddenfields = '';
+               $fieldlist = Array();
                $propertyOverride = Array();
                $fieldname_hashArray = Array();
-               $cc=0;
-               reset($dataArr);
-               while(list(,$val)=each($dataArr)) {
+               $cc = 0;
+
+               foreach($dataArr as $val)       {
                        $cc++;
                        $confData=Array();
                        if (is_array($formData)) {
                                $parts = $val;
-                               $val=1;    // true...
+                               $val = 1;    // true...
                        } else {
-                               $val=trim($val);
+                               $val = trim($val);
                                $parts = explode('|',$val);
                        }
                        if ($val && strcspn($val,'#/')) {
@@ -1688,7 +1691,7 @@ class tslib_cObj {
                                                        $confData['fieldname'], htmlspecialchars($value));
                                        break;
                                        case 'property':
-                                               if (t3lib_div::inList('type,locationData,goodMess,badMess',$confData['fieldname']))     {
+                                               if (t3lib_div::inList('type,locationData,goodMess,badMess,emailMess',$confData['fieldname']))   {
                                                        $value=trim($parts[2]);
                                                        $propertyOverride[$confData['fieldname']] = $value;
                                                        $conf[$confData['fieldname']] = $value;
@@ -1713,6 +1716,39 @@ class tslib_cObj {
                                        break;
                                }
                                if ($fieldCode) {
+
+                                               // Checking for special evaluation modes:
+                                       if (t3lib_div::inList('textarea,input,password',$confData['type']) && strlen(trim($parts[3])))  {
+                                               $modeParameters = t3lib_div::trimExplode(':',$parts[3]);
+                                       } else {
+                                               $modeParameters = array();
+                                       }
+
+                                               // Adding evaluation based on settings:
+                                       switch((string)$modeParameters[0])      {
+                                               case 'EREG':
+                                                       $fieldlist[] = '_EREG';
+                                                       $fieldlist[] = rawurlencode($modeParameters[1]);
+                                                       $fieldlist[] = rawurlencode($modeParameters[2]);
+                                                       $fieldlist[] = rawurlencode($confData['fieldname']);
+                                                       $fieldlist[] = rawurlencode($confData['label']);
+                                                       $confData['required'] = 1;      // Setting this so "required" layout is used.
+                                               break;
+                                               case 'EMAIL':
+                                                       $fieldlist[] = '_EMAIL';
+                                                       $fieldlist[] = rawurlencode($confData['fieldname']);
+                                                       $fieldlist[] = rawurlencode($confData['label']);
+                                                       $confData['required'] = 1;      // Setting this so "required" layout is used.
+                                               break;
+                                               default:
+                                                       if ($confData['required'] && $confData['type']!='check')        {
+                                                               $fieldlist[] = rawurlencode($confData['fieldname']);
+                                                               $fieldlist[] = rawurlencode($confData['label']);
+                                                       }
+                                               break;
+                                       }
+
+                                               // Getting template code:
                                        $fieldCode = $this->stdWrap($fieldCode, $conf['fieldWrap.']);
                                        $labelCode = $this->stdWrap($confData['label'], $conf['labelWrap.']);
                                        $commentCode = $this->stdWrap($confData['label'], $conf['commentWrap.']); // RTF
@@ -1738,12 +1774,7 @@ class tslib_cObj {
                                        $result = str_replace('###FIELD###',$fieldCode,$result);
                                        $result = str_replace('###LABEL###',$labelCode,$result);
                                        $result = str_replace('###COMMENT###',$commentCode,$result); //RTF
-                                       $content.=$result;
-                                               // Required:
-                                       if ($confData['required'] && $confData['type']!='check')        {
-                                               $fieldlist[]=rawurlencode($confData['fieldname']);
-                                               $fieldlist[]=rawurlencode($confData['label']);
-                                       }
+                                       $content.= $result;
                                }
                        }
                }
@@ -1815,7 +1846,7 @@ class tslib_cObj {
                        // Formname;
                $formname = $GLOBALS['TSFE']->uniqueHash();
                if ($conf['REQ'])       {
-                       $validateForm=' onsubmit="return validateForm(\''.$formname.'\',\''.implode($fieldlist,',').'\',\''.rawurlencode($conf['goodMess']).'\',\''.rawurlencode($conf['badMess']).'\')"';
+                       $validateForm=' onsubmit="return validateForm(\''.$formname.'\',\''.implode($fieldlist,',').'\',\''.rawurlencode($conf['goodMess']).'\',\''.rawurlencode($conf['badMess']).'\',\''.rawurlencode($conf['emailMess']).'\')"';
                        $GLOBALS['TSFE']->additionalHeaderData['JSFormValidate'] = '<script type="text/javascript" src="'.$GLOBALS['TSFE']->absRefPrefix.'t3lib/jsfunc.validateform.js"></script>';
                } else $validateForm='';
 
index 8d8aac9..d3bb4f6 100755 (executable)
@@ -42,6 +42,7 @@ $LOCAL_LANG = Array (
                'forms_type_radio' => 'Radio buttons',
                'forms_type_hidden' => 'Hidden value',
                'forms_type_submit' => 'Submit Button',
+               'forms_type_property' => 'Property',
                'forms_required' => 'Required',
                'forms_fieldName' => 'Field',
                'forms_cols' => 'Columns',
index 9073ad3..2b98af9 100755 (executable)
@@ -424,7 +424,7 @@ class SC_wizard_forms {
                                                // Field type selector:
                                        $opt=array();
                                        $opt[]='<option value=""></option>';
-                                       $types = explode(',','input,textarea,select,check,radio,password,file,hidden,submit');
+                                       $types = explode(',','input,textarea,select,check,radio,password,file,hidden,submit,property');
                                        foreach($types as $t)   {
                                                $opt[]='
                                                                <option value="'.$t.'"'.($confData['type']==$t?' selected="selected"':'').'>'.$LANG->getLL('forms_type_'.$t,1).'</option>';
@@ -441,7 +441,7 @@ class SC_wizard_forms {
                                        }
 
                                                // Required checkbox:
-                                       if (!t3lib_div::inList(',hidden,submit',$confData['type']))             {
+                                       if (!t3lib_div::inList('check,hidden,submit',$confData['type']))                {
                                                $temp_cells[$LANG->getLL('forms_required')]='<input type="checkbox" name="FORMCFG[c]['.(($k+1)*2).'][required]" value="1"'.($confData['required']?' checked="checked"':'').' title="'.$LANG->getLL('forms_required',1).'" />';
                                        }
 
@@ -480,6 +480,17 @@ class SC_wizard_forms {
                                                break;
                                        }
 
+                                               // Field configuration depending on the fields type:
+                                       switch((string)$confData['type'])       {
+                                               case 'textarea':
+                                               case 'input':
+                                               case 'password':
+                                                       if (strlen(trim($confData['specialEval'])))     {
+                                                               $hiddenFields[] = '<input type="hidden" name="FORMCFG[c]['.(($k+1)*2).'][specialEval]" value="'.htmlspecialchars($confData['specialEval']).'" />';
+                                                       }
+                                               break;
+                                       }
+
                                                // Default data
                                        if ($confData['type']=='select' || $confData['type']=='radio')  {
                                                $temp_cells[$LANG->getLL('forms_options')]='<textarea '.$this->doc->formWidthText(15).' rows="4" name="FORMCFG[c]['.(($k+1)*2).'][options]" title="'.$LANG->getLL('forms_options',1).'">'.t3lib_div::formatForTextarea($confData['default']).'</textarea>';
@@ -722,11 +733,19 @@ class SC_wizard_forms {
                                                        if (intval($vv['cols']))        $tArr[0]=intval($vv['cols']);
                                                        if (intval($vv['rows']))        $tArr[1]=intval($vv['rows']);
                                                        if (trim($vv['extra']))         $tArr[2]=trim($vv['extra']);
+                                                       if (strlen($vv['specialEval'])) {
+                                                               $thisLine[2] = '';      // Preset blank default value so position 3 can get a value...
+                                                               $thisLine[3] = $vv['specialEval'];
+                                                       }
                                                break;
                                                case 'input':
                                                case 'password':
                                                        if (intval($vv['size']))        $tArr[0]=intval($vv['size']);
                                                        if (intval($vv['max']))         $tArr[1]=intval($vv['max']);
+                                                       if (strlen($vv['specialEval'])) {
+                                                               $thisLine[2] = '';      // Preset blank default value so position 3 can get a value...
+                                                               $thisLine[3] = $vv['specialEval'];
+                                                       }
                                                break;
                                                case 'file':
                                                        if (intval($vv['size']))        $tArr[0]=intval($vv['size']);
@@ -757,7 +776,6 @@ class SC_wizard_forms {
                                $inLines[]=ereg_replace("[\n\r]*",'',implode(' | ',$thisLine));
                        }
                }
-
                        // Finally, implode the lines into a string, and return it:
                return implode(chr(10),$inLines);
        }
@@ -828,11 +846,13 @@ class SC_wizard_forms {
                                                        $confData['cols'] = $fParts[1];
                                                        $confData['rows'] = $fParts[2];
                                                        $confData['extra'] = strtoupper($fParts[3])=='OFF' ? 'OFF' : '';
+                                                       $confData['specialEval'] = trim($parts[3]);
                                                break;
                                                case 'input':
                                                case 'password':
                                                        $confData['size'] = $fParts[1];
                                                        $confData['max'] = $fParts[2];
+                                                       $confData['specialEval'] = trim($parts[3]);
                                                break;
                                                case 'file':
                                                        $confData['size'] = $fParts[1];