]> Dogcows Code - chaz/p5-CGI-Ex/blobdiff - lib/CGI/Ex/validate.js
CGI::Ex 2.08
[chaz/p5-CGI-Ex] / lib / CGI / Ex / validate.js
index 8d4c296aee4d37ab42bc9221799dd53121164813..8ac047976a473c7fc9ab25ca4e8a3906a58958a4 100644 (file)
@@ -1,10 +1,10 @@
 /**----------------------------------------------------------------***
-*  Copyright 2004 - Paul Seamons                                     *
+*  Copyright 2007 - Paul Seamons                                     *
 *  Distributed under the Perl Artistic License without warranty      *
 *  Based upon CGI/Ex/Validate.pm v1.14 from Perl                     *
 *  For instructions on usage, see perldoc of CGI::Ex::Validate       *
 ***----------------------------------------------------------------**/
-// $Revision: 1.31 $
+// $Revision: 1.41 $
 
 function Validate () {
  this.error             = vob_error;
@@ -60,7 +60,10 @@ function vob_validate (form, val_hash) {
    /// look for a group order and then fail back to the keys of the group
    var fields = group_val['group fields'];
    var order  = new Array();
-   for (var key in group_val) order[order.length] = key;
+   for (var key in group_val) {
+     if (key == 'extend') continue; // Protoype Array() fix
+     order[order.length] = key;
+   }
    order = order.sort();
    if (fields) {
      if (typeof(fields) != 'object' || ! fields.length)
@@ -151,6 +154,7 @@ function vob_validate (form, val_hash) {
 
  /// store any extra items from self
  for (var key in this) {
+   if (key == 'extend') continue; // Protoype Array() fix
    if (! key.match('_error$')
        && ! key.match('^(raise_error|as_hash_\\w+|as_array_\\w+|as_string_\\w+)$')) continue;
    EXTRA[key] = this[key];
@@ -241,7 +245,10 @@ function vob_validate_buddy (form, field, field_val, N_level, ifs_match) {
 
  var errors = new Array();
  var types  = new Array();
- for (var key in field_val) types[types.length] = key;
+ for (var key in field_val) {
+   if (key == 'extend') continue; // Protoype Array() fix
+   types[types.length] = key;
+ }
  types = types.sort();
 
  /// allow for not running some tests in the cgi
@@ -284,8 +291,10 @@ function vob_validate_buddy (form, field, field_val, N_level, ifs_match) {
  if (n_values == 0 || (n_values == 1 && values[0].length == 0)) {
    for (var i = 0; i < tests.length; i ++) {
      var el = form[field];
+     if (! el) continue;
      var type = el.type;
-     if (type && (type == 'hidden' || type == 'password' || type == 'text' || type == 'textarea' || type == 'submit')) el.value = values[0] = field_val[tests[i]];
+     if (type && (type == 'hidden' || type == 'password' || type == 'text' || type == 'textarea' || type == 'submit'))
+       el.value = values[0] = '' + field_val[tests[i]];
    }
  }
 
@@ -295,6 +304,8 @@ function vob_validate_buddy (form, field, field_val, N_level, ifs_match) {
    if (typeof(values[i]) == 'undefined') continue;
    if (! this.filter_types('do_not_trim',types).length)
      values[i] = values[i].replace('^\\s+','').replace(new RegExp('\\s+$',''),'');
+   if (this.filter_types('trim_control_chars',types).length)
+     values[i] = values[i].replace(new RegExp('\t', 'g'),' ').replace(new RegExp('[\\x00-\\x1F]+','g'),'');
    if (this.filter_types('to_upper_case',types).length) {
      values[i] = values[i].toUpperCase();
    } else if (this.filter_types('to_lower_case',types).length) {
@@ -570,9 +581,9 @@ function vob_check_type (value, type, field, form) {
  /// the "username" portion of an email address
  } else if (type == 'LOCAL_PART') {
    if (typeof(value) == 'undefined' || ! value.length) return 0;
-   if (! value.match('[^a-z0-9.\\-!&]')) return 0;
-   if (! value.match('^[.\\-]'))         return 0;
-   if (! value.match('[.\\-&]$'))        return 0;
+   if (! value.match('[^a-z0-9.\\-!&+]'))   return 0;
+   if (! value.match('^[.\\-]'))            return 0;
+   if (! value.match('[.\\-&]$'))           return 0;
    if (! value.match('(\\.-|-\\.|\\.\\.)')) return 0;
 
  /// standard IP address
@@ -771,7 +782,10 @@ function eob_as_hash (extra2) {
  if (joiner) {
    var header = eob_get_val('as_hash_header', extra2, extra1, '');
    var footer = eob_get_val('as_hash_footer', extra2, extra1, '');
-   for (var key in ret) ret[key] = header + ret[key].join(joiner) + footer;
+   for (var key in ret) {
+     if (key == 'extend') continue; // Protoype Array() fix
+     ret[key] = header + ret[key].join(joiner) + footer;
+   }
  }
 
  return ret;
@@ -913,6 +927,7 @@ document.validate = function (form, val_hash) {
  // undo previous inline
  if (document.did_inline) {
    for (var key in document.did_inline) {
+     if (key == 'extend') continue; // Protoype Array() fix
      var el = document.getElementById(key);
      if (el) el.innerHTML = '';
    }
@@ -937,6 +952,7 @@ document.validate = function (form, val_hash) {
    var d = document.did_inline = new Array();
    var hash = err_obj.as_hash();
    for (var key in hash) {
+     if (key == 'extend') continue; // Protoype Array() fix
      var el = document.getElementById(key);
      if (el) el.innerHTML = hash[key];
      d[key] = 1;
@@ -1035,7 +1051,8 @@ document.check_form = function (form, val_hash) {
  document.load_val_hash(form, val_hash);
 
  // attach handler
- form.onsubmit = function () {return document.validate(this)};
+ var orig_submit = form.onsubmit || function () { return true };
+ form.onsubmit = function (e) { return document.validate(this) && orig_submit(e, this) };
 }
 
 // the end //
This page took 0.027504 seconds and 4 git commands to generate.