|
ulf-wendel.de   
|
|
 Home < PHP Schulung  < OOH Forms  < JavaScript  < JS-Codevariante I    |       |  
Print Version    
---
|
|
 Home 
 PHP Projekte 
 PHP Schulung 
    Informationsquellen 
    Geschichte 
    Core PHP 
    Fortgeschrittenes PHP 
    Templates 
    Cache-Technologien 
    OOH Forms 
       Grundlagen 
       JavaScript 
          Aktivierung 
          Validierungstypen 
          JS-Codevariante I 
          JS-Codevariante II 
          JS_README 
          Custom Validators 
          Custom Validators II 
       XML 
       Layoutmanager 
       Pages 
       Wizards 
       Fazit 
 Technik der Site 
 Büchertipps 
 Fotografie 
 Airbrush 
 Kontakt 
 Stuff 

Code für einfache Validierungen

Die JavaScript Validierung erfolgt mittels zweier Klassen. Eine für einfache Validierungen ohne Custom-Validators und eine für solche mit Custom-Validators.

Die Entscheidung objektorientierten Code zu verwenden fiel vor dem Hintergrund, daß in einem HTML-Dokument mehrere Formulare enthalten sein können. Ist dies der Fall, soll das System den Basiscode nur einmal einfügen. Es stehen allerding noch keine API Funktionen zur Verfügung, die dies erlauben.

Die Größe des JavaScript Code wird bei der Ausgabe mittels der Methode compressJS() durch die Entfernung von Leerzeichen reduziert.


Basiscode Top

<?php
 
require_once('HTML_OOH_Form/form.php');
 
define('FORM_FILE_DIR'$DOCUMENT_ROOT '/projekte/');
 
 
// alle File-Funktionen in den OOH-Forms benutzen die Konstante 
 // FORM_FILE_DIR
 
$code implode(''file(FORM_FILE_DIR 'HTML_OOH_Form/js/form_js_simple.js'));
 
$code preg_replace('/\t/''  '$code);
 
 
printf("Basiscode [%d Bytes]:\n\n%s\n\n"
        
strlen($code),
        
$code
      
);

  
// private void compressJS(string $js) demonstrieren
  
$code form::compressJS($code);
  
printf("Komprimiert [%d Bytes]:\n\n%s",
          
strlen($code),
          
$code
       
);
?>
Ausgabe Top
Basiscode [1252 Bytes]:

function form(n, els) {
  this.name = n;
  this.els = els;
  this.p = "";
};
new form;

form.prototype.validate = function () {

  var e = f = s = "";
  var i, el, vd, j, vl, c, l, a, d, n;
  n = this.name;
  d = this.els;

  for (i = 0; i < d.length; i += 2) {
    el = this.p + d[i];

    a = arguments;
    if (a.length && a[0] != el)
      continue;

    vd = d[i + 1];
    vl = document.forms[n].elements[el].value;

    j = 0;
    while (j < vd.length) {

      c = vd[j];
      j += 4;

      if ("v" == c) {
        eval("vl = " + vd[j - 3] + "('" + n + "', '" + el + "'); j -= 2;");
        s = vl[1];
        vl = vl[0];
      }

      l = vl.length;
      if ("l" == c && (l < vd[j - 3] || (vd[j -2] >= 0 && l > vd[j - 2])))
        e += vd[j - 1] + "\n";

      if ("r" == c && -1 == vl.search(new RegExp(vd[j - 3], vd[j - 2])))
        e += vd[j - 1] + "\n";

      if ("i" == c && -1 != vl.search(new RegExp(vd[j - 3])))
        e += vd[j-- - 2] + "\n";
      
    }

    if (!f && e)
      f = (s) ? s : el;
  }

  if (e) {
    alert("" + e + "");
    document.forms[n].elements[f].focus();
    return false;
  }
  return true;
};

Komprimiert [790 Bytes]:

function form(n,els){this.name=n;this.els=els;this.p="";
};new form;form.prototype.validate=function (){var e=f=s="";
var i,el,vd,j,vl,c,l,a,d,n;n=this.name;d=this.els;for(i=0;i=0&&l>vd[j-2])))
e+=vd[j-1]+"\n";if("r"==c&&-1==vl.search(new RegExp(vd[j-3],vd[j-2])))
e+=vd[j-1]+"\n";if("i"==c&&-1!=vl.search(new RegExp(vd[j-3])))
e+=vd[j---2]+"\n";}if(!f&&e)f=(s)?s:el;}if(e){alert(""+e+"");
document.forms[n].elements[f].focus();return false;}return true;
};

<  ^  >

 Neues

 XML/XSLT Menu
 OOH-Form Rewrite

 PEAR Cache:
  SHM Container

 Suchstring Parser
 Buchrezensionen
 PEAR Cache:
  OutputCompression

 PEAR Menu Browser
 PEAR Menu Tutorial 
 PEAR Cache


 Tipp

Download Version:
oben rechts,
Download *.tar.gz
|
| --- |
|
  Top   |   <  ^  >   |   phpOpenTracker Statistik   |   URL: http://www.ulf-wendel.de/schulung/ooh/js/code1.php   |   Stand: 16.11.2001   |   © Ulf Wendel   
|
| --- |

0.026 s Bearbeitungszeit, 0.002 s IT[X], 0.005 s Menu 3