[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/includes/javascript/ -> form_check.js.php (source)

   1  <?php
   2  /*

   3  $Id: form_check.js.php 3 2006-05-27 04:59:07Z user $

   4  

   5    osCMax Power E-Commerce

   6    http://oscdox.com

   7  

   8    Copyright 2006 osCMax

   9  

  10    Released under the GNU General Public License

  11  */
  12  ?>
  13  <script language="javascript" type="text/javascript"><!--
  14  var form = "";
  15  var submitted = false;
  16  var error = false;
  17  var error_message = "";
  18  
  19  function check_input(field_name, field_size, message) {
  20    if (form.elements[field_name] && (form.elements[field_name].type != "hidden")) {
  21      var field_value = form.elements[field_name].value;
  22  
  23  // LINE MOD: added 'field_size >0 &&'

  24      if ((field_size > 0 && field_value == '') || field_value.length < field_size) {
  25        error_message = error_message + "* " + message + "\n";
  26        error = true;
  27      }
  28    }
  29  }
  30  
  31  function check_radio(field_name, message) {
  32    var isChecked = false;
  33  
  34    if (form.elements[field_name] && (form.elements[field_name].type != "hidden")) {
  35      var radio = form.elements[field_name];
  36  
  37      for (var i=0; i<radio.length; i++) {
  38        if (radio[i].checked == true) {
  39          isChecked = true;
  40          break;
  41        }
  42      }
  43  
  44      if (isChecked == false) {
  45        error_message = error_message + "* " + message + "\n";
  46        error = true;
  47      }
  48    }
  49  }
  50  
  51  function check_select(field_name, field_default, message) {
  52    if (form.elements[field_name] && (form.elements[field_name].type != "hidden")) {
  53      var field_value = form.elements[field_name].value;
  54  
  55      if (field_value == field_default) {
  56        error_message = error_message + "* " + message + "\n";
  57        error = true;
  58      }
  59    }
  60  }
  61  
  62  function check_password(field_name_1, field_name_2, field_size, message_1, message_2) {
  63    if (form.elements[field_name_1] && (form.elements[field_name_1].type != "hidden")) {
  64      var password = form.elements[field_name_1].value;
  65      var confirmation = form.elements[field_name_2].value;
  66  
  67      if (password == '' || password.length < field_size) {
  68        error_message = error_message + "* " + message_1 + "\n";
  69        error = true;
  70      } else if (password != confirmation) {
  71        error_message = error_message + "* " + message_2 + "\n";
  72        error = true;
  73      }
  74    }
  75  }
  76  
  77  function check_password_new(field_name_1, field_name_2, field_name_3, field_size, message_1, message_2, message_3) {
  78    if (form.elements[field_name_1] && (form.elements[field_name_1].type != "hidden")) {
  79      var password_current = form.elements[field_name_1].value;
  80      var password_new = form.elements[field_name_2].value;
  81      var password_confirmation = form.elements[field_name_3].value;
  82  
  83      if (password_current == '' || password_current.length < field_size) {
  84        error_message = error_message + "* " + message_1 + "\n";
  85        error = true;
  86      } else if (password_new == '' || password_new.length < field_size) {
  87        error_message = error_message + "* " + message_2 + "\n";
  88        error = true;
  89      } else if (password_new != password_confirmation) {
  90        error_message = error_message + "* " + message_3 + "\n";
  91        error = true;
  92      }
  93    }
  94  }
  95  
  96  function check_form(form_name) {
  97    if (submitted == true) {
  98      alert("<?php echo JS_ERROR_SUBMITTED; ?>");
  99      return false;
 100    }
 101  
 102    error = false;
 103    form = form_name;
 104    error_message = "<?php echo JS_ERROR; ?>";
 105  
 106  <?php if (ACCOUNT_GENDER == 'true') echo '  check_radio("gender", "' . ENTRY_GENDER_ERROR . '");' . "\n"; ?>
 107  
 108    check_input("firstname", <?php echo ENTRY_FIRST_NAME_MIN_LENGTH; ?>, "<?php echo ENTRY_FIRST_NAME_ERROR; ?>");
 109    check_input("lastname", <?php echo ENTRY_LAST_NAME_MIN_LENGTH; ?>, "<?php echo ENTRY_LAST_NAME_ERROR; ?>");
 110  
 111  <?php if (ACCOUNT_DOB == 'true') echo '  check_input("dob", ' . ENTRY_DOB_MIN_LENGTH . ', "' . ENTRY_DATE_OF_BIRTH_ERROR . '");' . "\n"; ?>
 112  
 113    check_input("email_address", <?php echo ENTRY_EMAIL_ADDRESS_MIN_LENGTH; ?>, "<?php echo ENTRY_EMAIL_ADDRESS_ERROR; ?>");
 114    check_input("street_address", <?php echo ENTRY_STREET_ADDRESS_MIN_LENGTH; ?>, "<?php echo ENTRY_STREET_ADDRESS_ERROR; ?>");
 115    check_input("postcode", <?php echo ENTRY_POSTCODE_MIN_LENGTH; ?>, "<?php echo ENTRY_POST_CODE_ERROR; ?>");
 116    check_input("city", <?php echo ENTRY_CITY_MIN_LENGTH; ?>, "<?php echo ENTRY_CITY_ERROR; ?>");
 117  
 118  <?php if (ACCOUNT_STATE == 'true') echo '  check_input("state", ' . ENTRY_STATE_MIN_LENGTH . ', "' . ENTRY_STATE_ERROR . '");' . "\n"; ?>
 119  
 120    check_select("country", "", "<?php echo ENTRY_COUNTRY_ERROR; ?>");
 121  
 122    check_input("telephone", <?php echo ENTRY_TELEPHONE_MIN_LENGTH; ?>, "<?php echo ENTRY_TELEPHONE_NUMBER_ERROR; ?>");
 123  
 124    check_password("password", "confirmation", <?php echo ENTRY_PASSWORD_MIN_LENGTH; ?>, "<?php echo ENTRY_PASSWORD_ERROR; ?>", "<?php echo ENTRY_PASSWORD_ERROR_NOT_MATCHING; ?>");
 125    check_password_new("password_current", "password_new", "password_confirmation", <?php echo ENTRY_PASSWORD_MIN_LENGTH; ?>, "<?php echo ENTRY_PASSWORD_ERROR; ?>", "<?php echo ENTRY_PASSWORD_NEW_ERROR; ?>", "<?php echo ENTRY_PASSWORD_NEW_ERROR_NOT_MATCHING; ?>");
 126  
 127    if (error == true) {
 128      alert(error_message);
 129      return false;
 130    } else {
 131      submitted = true;
 132      return true;
 133    }
 134  }
 135  <?php /* BOF: Country-State Selector */ ?>
 136  function refresh_form(form_name) {
 137     form_name.action.value = 'refresh';
 138     form_name.state.value = '';
 139     form_name.submit();
 140     return true;
 141     }
 142  <?php /* EOF: Country-State Selector */ ?>
 143  //--></script>



Generated: Fri Jan 1 13:43:16 2010 Cross-referenced by PHPXref 0.7