client-side validation
This commit is contained in:
parent
7649a52134
commit
43a82b487e
|
@ -139,8 +139,10 @@ D:
|
||||||
Programs and licenses with other licenses and/or authors than the
|
Programs and licenses with other licenses and/or authors than the
|
||||||
main license and authors:
|
main license and authors:
|
||||||
|
|
||||||
lib/fpdf.php A 2008 Olivier Plathey
|
lib/fpdf.php A 2008 Olivier Plathey
|
||||||
lib/font/Vera* B 2003 Bitstream, Inc.
|
lib/font/Vera* B 2003 Bitstream, Inc.
|
||||||
templates/lib/wz_tooltip.js C Walter Zorn
|
templates/lib/*wz_tooltip.js C Walter Zorn
|
||||||
templates/lib/jquery*.js D 2010 John Resig, Paul Bakaus, Fred Heusschen
|
lib/3rdParty/phpseclib C Jim Wigginton
|
||||||
lib/3rdParty/phpseclib C Jim Wigginton
|
templates/lib/*jquery*.js D 2010 John Resig, Paul Bakaus, Fred Heusschen
|
||||||
|
templates/lib/*jquery-validationEngine-*.js D 2010 Cedric Dugas and Olivier Refalo
|
||||||
|
|
||||||
|
|
|
@ -36,14 +36,20 @@ $Id$
|
||||||
*/
|
*/
|
||||||
abstract class htmlElement {
|
abstract class htmlElement {
|
||||||
|
|
||||||
const OPTION_ALIGN = 0;
|
/** align to top */
|
||||||
|
|
||||||
const ALIGN_TOP = 0;
|
const ALIGN_TOP = 0;
|
||||||
|
/** align to left */
|
||||||
const ALIGN_LEFT = 1;
|
const ALIGN_LEFT = 1;
|
||||||
|
/** align to right */
|
||||||
const ALIGN_RIGHT = 2;
|
const ALIGN_RIGHT = 2;
|
||||||
|
/** align to bottom */
|
||||||
const ALIGN_BOTTOM = 3;
|
const ALIGN_BOTTOM = 3;
|
||||||
|
/** align to center */
|
||||||
const ALIGN_CENTER = 4;
|
const ALIGN_CENTER = 4;
|
||||||
|
|
||||||
|
/** validation rule to allow only numbers ([0-9]+) */
|
||||||
|
const VALIDATE_NUMERIC = 'numeric';
|
||||||
|
|
||||||
/** alignment when inside a table */
|
/** alignment when inside a table */
|
||||||
public $alignment = null;
|
public $alignment = null;
|
||||||
/** colspan if inside a table */
|
/** colspan if inside a table */
|
||||||
|
@ -351,6 +357,10 @@ class htmlInputField extends htmlElement {
|
||||||
private $isEnabled = true;
|
private $isEnabled = true;
|
||||||
/** indicates that the value should be saved in obfuscated form */
|
/** indicates that the value should be saved in obfuscated form */
|
||||||
private $obfuscate = false;
|
private $obfuscate = false;
|
||||||
|
/** required field */
|
||||||
|
protected $required = false;
|
||||||
|
/** validation rule */
|
||||||
|
private $validationRule = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
|
@ -389,8 +399,20 @@ class htmlInputField extends htmlElement {
|
||||||
$this->fieldValue = $values[$this->fieldName][0];
|
$this->fieldValue = $values[$this->fieldName][0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$validators = array();
|
||||||
|
if ($this->required) {
|
||||||
|
$validators[] = 'required';
|
||||||
|
}
|
||||||
|
if ($this->validationRule != null) {
|
||||||
|
$validators[] = 'custom[' . $this->validationRule . ']';
|
||||||
|
}
|
||||||
// print input field
|
// print input field
|
||||||
|
$class = '';
|
||||||
|
if (sizeof($validators) > 0) {
|
||||||
|
$class = ' class="validate[' . implode(',', $validators) . ']"';
|
||||||
|
}
|
||||||
$name = ' name="' . $this->fieldName . '"';
|
$name = ' name="' . $this->fieldName . '"';
|
||||||
|
$id = ' id="inputField_' . $this->fieldName . '"';
|
||||||
$value = '';
|
$value = '';
|
||||||
if ($this->fieldValue != null) {
|
if ($this->fieldValue != null) {
|
||||||
$value = ' value="' . $this->fieldValue . '"';
|
$value = ' value="' . $this->fieldValue . '"';
|
||||||
|
@ -410,7 +432,7 @@ class htmlInputField extends htmlElement {
|
||||||
if (!$this->isEnabled) {
|
if (!$this->isEnabled) {
|
||||||
$disabled = ' disabled';
|
$disabled = ' disabled';
|
||||||
}
|
}
|
||||||
echo '<input type="' . $inputType . '"' . $name . $value . $maxLength . $size . $fieldTabIndex . $disabled . '>';
|
echo '<input type="' . $inputType . '"' . $class . $name . $id . $value . $maxLength . $size . $fieldTabIndex . $disabled . '>';
|
||||||
if ($this->obfuscate) {
|
if ($this->obfuscate) {
|
||||||
return array($this->fieldName => 'text_obfuscated');
|
return array($this->fieldName => 'text_obfuscated');
|
||||||
}
|
}
|
||||||
|
@ -464,6 +486,25 @@ class htmlInputField extends htmlElement {
|
||||||
$this->obfuscate = $obfuscate;
|
$this->obfuscate = $obfuscate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies if the input field is required.
|
||||||
|
*
|
||||||
|
* @param boolean $required required
|
||||||
|
*/
|
||||||
|
public function setRequired($required) {
|
||||||
|
$this->required = $required;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies the validation rule (e.g. htmlElement::VALIDATE_NUMERIC) for this field.
|
||||||
|
* This rule is checked on client side when the input field looses focus.
|
||||||
|
*
|
||||||
|
* @param boolean $rule rule name
|
||||||
|
*/
|
||||||
|
public function setValidationRule($rule) {
|
||||||
|
$this->validationRule = $rule;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -477,8 +518,6 @@ class htmlTableExtendedInputField extends htmlInputField {
|
||||||
private $label;
|
private $label;
|
||||||
/** help ID */
|
/** help ID */
|
||||||
private $helpID;
|
private $helpID;
|
||||||
/** required field */
|
|
||||||
private $required = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
|
@ -527,15 +566,6 @@ class htmlTableExtendedInputField extends htmlInputField {
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Specifies if this input field must be filled.
|
|
||||||
*
|
|
||||||
* @param boolean $required required or not
|
|
||||||
*/
|
|
||||||
public function setRequired($required) {
|
|
||||||
$this->required = $required;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1159,7 +1159,12 @@ class accountContainer {
|
||||||
*/
|
*/
|
||||||
private function printPageHeader() {
|
private function printPageHeader() {
|
||||||
include '../main_header.php';
|
include '../main_header.php';
|
||||||
echo "<form enctype=\"multipart/form-data\" action=\"edit.php\" method=\"post\">\n";
|
echo '<script type="text/javascript">';
|
||||||
|
echo 'jQuery(document).ready(function() {';
|
||||||
|
echo ' jQuery("#inputForm").validationEngine();';
|
||||||
|
echo '});';
|
||||||
|
echo '</script>';
|
||||||
|
echo "<form id=\"inputForm\" enctype=\"multipart/form-data\" action=\"edit.php\" method=\"post\">\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1086,13 +1086,10 @@ class posixAccount extends baseModule implements passwordService {
|
||||||
$return->addElement($uidInput, true);
|
$return->addElement($uidInput, true);
|
||||||
$commonName = '';
|
$commonName = '';
|
||||||
if (isset($this->attributes['cn'][0])) $commonName = $this->attributes['cn'][0];
|
if (isset($this->attributes['cn'][0])) $commonName = $this->attributes['cn'][0];
|
||||||
$cnInput = new htmlTableExtendedInputField(_("Common name"), 'cn', $commonName, 'cn');
|
$return->addElement(new htmlTableExtendedInputField(_("Common name"), 'cn', $commonName, 'cn'), true);
|
||||||
$cnInput->setRequired(true);
|
|
||||||
$return->addElement($cnInput, true);
|
|
||||||
$uidNumber = '';
|
$uidNumber = '';
|
||||||
if (isset($this->attributes['uidNumber'][0])) $uidNumber = $this->attributes['uidNumber'][0];
|
if (isset($this->attributes['uidNumber'][0])) $uidNumber = $this->attributes['uidNumber'][0];
|
||||||
$uidNumberInput = new htmlTableExtendedInputField(_('UID number'), 'uidNumber', $uidNumber, 'uidNumber');
|
$uidNumberInput = new htmlTableExtendedInputField(_('UID number'), 'uidNumber', $uidNumber, 'uidNumber');
|
||||||
$uidNumberInput->setRequired(true);
|
|
||||||
$uidNumberInput->setFieldMaxLength(20);
|
$uidNumberInput->setFieldMaxLength(20);
|
||||||
$return->addElement($uidNumberInput, true);
|
$return->addElement($uidNumberInput, true);
|
||||||
$gecos = '';
|
$gecos = '';
|
||||||
|
|
|
@ -305,6 +305,7 @@ class shadowAccount extends baseModule implements passwordService {
|
||||||
$pwdWarnInput = new htmlTableExtendedInputField(_('Password warning'), 'shadowWarning', $shWarning, 'shadowWarning');
|
$pwdWarnInput = new htmlTableExtendedInputField(_('Password warning'), 'shadowWarning', $shWarning, 'shadowWarning');
|
||||||
$pwdWarnInput->setFieldMaxLength(4);
|
$pwdWarnInput->setFieldMaxLength(4);
|
||||||
$pwdWarnInput->setFieldSize(5);
|
$pwdWarnInput->setFieldSize(5);
|
||||||
|
$pwdWarnInput->setValidationRule(htmlElement::VALIDATE_NUMERIC);
|
||||||
$return->addElement($pwdWarnInput, true);
|
$return->addElement($pwdWarnInput, true);
|
||||||
|
|
||||||
$shPwdExpiration = '';
|
$shPwdExpiration = '';
|
||||||
|
@ -312,6 +313,7 @@ class shadowAccount extends baseModule implements passwordService {
|
||||||
$pwdExpInput = new htmlTableExtendedInputField(_('Password expiration'), 'shadowInactive', $shPwdExpiration, 'shadowInactive');
|
$pwdExpInput = new htmlTableExtendedInputField(_('Password expiration'), 'shadowInactive', $shPwdExpiration, 'shadowInactive');
|
||||||
$pwdExpInput->setFieldMaxLength(4);
|
$pwdExpInput->setFieldMaxLength(4);
|
||||||
$pwdExpInput->setFieldSize(5);
|
$pwdExpInput->setFieldSize(5);
|
||||||
|
$pwdExpInput->setValidationRule(htmlElement::VALIDATE_NUMERIC);
|
||||||
$return->addElement($pwdExpInput, true);
|
$return->addElement($pwdExpInput, true);
|
||||||
|
|
||||||
$shMinAge = '';
|
$shMinAge = '';
|
||||||
|
@ -319,6 +321,7 @@ class shadowAccount extends baseModule implements passwordService {
|
||||||
$minAgeInput = new htmlTableExtendedInputField(_('Minimum password age'), 'shadowMin', $shMinAge, 'shadowMin');
|
$minAgeInput = new htmlTableExtendedInputField(_('Minimum password age'), 'shadowMin', $shMinAge, 'shadowMin');
|
||||||
$minAgeInput->setFieldMaxLength(5);
|
$minAgeInput->setFieldMaxLength(5);
|
||||||
$minAgeInput->setFieldSize(5);
|
$minAgeInput->setFieldSize(5);
|
||||||
|
$minAgeInput->setValidationRule(htmlElement::VALIDATE_NUMERIC);
|
||||||
$return->addElement($minAgeInput, true);
|
$return->addElement($minAgeInput, true);
|
||||||
|
|
||||||
$shMaxAge = '';
|
$shMaxAge = '';
|
||||||
|
@ -326,6 +329,7 @@ class shadowAccount extends baseModule implements passwordService {
|
||||||
$maxAgeInput = new htmlTableExtendedInputField(_('Maximum password age'), 'shadowMax', $shMaxAge, 'shadowMax');
|
$maxAgeInput = new htmlTableExtendedInputField(_('Maximum password age'), 'shadowMax', $shMaxAge, 'shadowMax');
|
||||||
$maxAgeInput->setFieldMaxLength(5);
|
$maxAgeInput->setFieldMaxLength(5);
|
||||||
$maxAgeInput->setFieldSize(5);
|
$maxAgeInput->setFieldSize(5);
|
||||||
|
$maxAgeInput->setValidationRule(htmlElement::VALIDATE_NUMERIC);
|
||||||
$return->addElement($maxAgeInput, true);
|
$return->addElement($maxAgeInput, true);
|
||||||
|
|
||||||
$expirationDate = " - ";
|
$expirationDate = " - ";
|
||||||
|
|
|
@ -0,0 +1,165 @@
|
||||||
|
/*
|
||||||
|
$Id$
|
||||||
|
|
||||||
|
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
|
||||||
|
Copyright (C) 2010 Cedric Dugas and Olivier Refalo
|
||||||
|
2011 Roland Gruber
|
||||||
|
|
||||||
|
This program 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 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program 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.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
.inputContainer {
|
||||||
|
position: relative;
|
||||||
|
float: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.formError {
|
||||||
|
position: absolute;
|
||||||
|
top: 300px;
|
||||||
|
left: 300px;
|
||||||
|
display: block;
|
||||||
|
z-index: 5000;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ajaxSubmit {
|
||||||
|
padding: 20px;
|
||||||
|
background: #55ea55;
|
||||||
|
border: 1px solid #999;
|
||||||
|
display: none
|
||||||
|
}
|
||||||
|
|
||||||
|
.formError .formErrorContent {
|
||||||
|
width: 100%;
|
||||||
|
background: #ee4f01;
|
||||||
|
position:relative;
|
||||||
|
z-index:5001;
|
||||||
|
color: #fff;
|
||||||
|
font-family: tahoma;
|
||||||
|
font-size: 12px;
|
||||||
|
border: 2px solid #ddd;
|
||||||
|
box-shadow: 0 0 6px #000;
|
||||||
|
-moz-box-shadow: 0 0 6px #000;
|
||||||
|
-webkit-box-shadow: 0 0 6px #000;
|
||||||
|
padding: 4px 10px 4px 10px;
|
||||||
|
border-radius: 6px;
|
||||||
|
-moz-border-radius: 6px;
|
||||||
|
-webkit-border-radius: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.greenPopup .formErrorContent {
|
||||||
|
background: #33be40;
|
||||||
|
}
|
||||||
|
|
||||||
|
.blackPopup .formErrorContent {
|
||||||
|
background: #393939;
|
||||||
|
color: #FFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
.formError .formErrorArrow {
|
||||||
|
width: 15px;
|
||||||
|
margin: -2px 0 0 13px;
|
||||||
|
position:relative;
|
||||||
|
z-index: 5006;
|
||||||
|
}
|
||||||
|
|
||||||
|
.formError .formErrorArrowBottom {
|
||||||
|
box-shadow: none;
|
||||||
|
-moz-box-shadow: none;
|
||||||
|
-webkit-box-shadow: none;
|
||||||
|
margin: 0px 0 0 12px;
|
||||||
|
top:2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.formError .formErrorArrow div {
|
||||||
|
border-left: 2px solid #ddd;
|
||||||
|
border-right: 2px solid #ddd;
|
||||||
|
box-shadow: 0 2px 3px #444;
|
||||||
|
-moz-box-shadow: 0 2px 3px #444;
|
||||||
|
-webkit-box-shadow: 0 2px 3px #444;
|
||||||
|
font-size: 0px;
|
||||||
|
height: 1px;
|
||||||
|
background: #ee4f01;
|
||||||
|
margin: 0 auto;
|
||||||
|
line-height: 0;
|
||||||
|
font-size: 0;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.formError .formErrorArrowBottom div {
|
||||||
|
box-shadow: none;
|
||||||
|
-moz-box-shadow: none;
|
||||||
|
-webkit-box-shadow: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.greenPopup .formErrorArrow div {
|
||||||
|
background: #33be40;
|
||||||
|
}
|
||||||
|
|
||||||
|
.blackPopup .formErrorArrow div {
|
||||||
|
background: #393939;
|
||||||
|
color: #FFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
.formError .formErrorArrow .line10 {
|
||||||
|
width: 15px;
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.formError .formErrorArrow .line9 {
|
||||||
|
width: 13px;
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.formError .formErrorArrow .line8 {
|
||||||
|
width: 11px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.formError .formErrorArrow .line7 {
|
||||||
|
width: 9px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.formError .formErrorArrow .line6 {
|
||||||
|
width: 7px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.formError .formErrorArrow .line5 {
|
||||||
|
width: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.formError .formErrorArrow .line4 {
|
||||||
|
width: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.formError .formErrorArrow .line3 {
|
||||||
|
width: 1px;
|
||||||
|
border-left: 2px solid #ddd;
|
||||||
|
border-right: 2px solid #ddd;
|
||||||
|
border-bottom: 0 solid #ddd;
|
||||||
|
}
|
||||||
|
|
||||||
|
.formError .formErrorArrow .line2 {
|
||||||
|
width: 3px;
|
||||||
|
border: none;
|
||||||
|
background: #ddd;
|
||||||
|
}
|
||||||
|
|
||||||
|
.formError .formErrorArrow .line1 {
|
||||||
|
width: 1px;
|
||||||
|
border: none;
|
||||||
|
background: #ddd;
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,44 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
$Id$
|
||||||
|
|
||||||
|
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
|
||||||
|
Copyright (C) 2010 Cedric Dugas and Olivier Refalo
|
||||||
|
2011 Roland Gruber
|
||||||
|
|
||||||
|
This program 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 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program 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.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
*/
|
||||||
|
?>
|
||||||
|
|
||||||
|
(function($){
|
||||||
|
$.fn.validationEngineLanguage = function(){
|
||||||
|
};
|
||||||
|
$.validationEngineLanguage = {
|
||||||
|
newLang: function(){
|
||||||
|
$.validationEngineLanguage.allRules = {
|
||||||
|
"required": {
|
||||||
|
"regex": "none",
|
||||||
|
"alertText": "<?php echo _('This field is required.'); ?>",
|
||||||
|
},
|
||||||
|
"numeric": {
|
||||||
|
"regex": /^[0-9]+$/,
|
||||||
|
"alertText": "<?php echo _('Please enter a number.') ?>"
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
$.validationEngineLanguage.newLang();
|
||||||
|
})(jQuery);
|
|
@ -57,7 +57,9 @@ $jsDirName = dirname(__FILE__) . '/lib';
|
||||||
$jsDir = dir($jsDirName);
|
$jsDir = dir($jsDirName);
|
||||||
$jsFiles = array();
|
$jsFiles = array();
|
||||||
while ($jsEntry = $jsDir->read()) {
|
while ($jsEntry = $jsDir->read()) {
|
||||||
if (substr($jsEntry, strlen($jsEntry) - 3, 3) != '.js') continue;
|
if ((substr($jsEntry, strlen($jsEntry) - 3, 3) != '.js') && (substr($jsEntry, strlen($jsEntry) - 4, 4) != '.php')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$jsFiles[] = $jsEntry;
|
$jsFiles[] = $jsEntry;
|
||||||
}
|
}
|
||||||
sort($jsFiles);
|
sort($jsFiles);
|
||||||
|
|
Loading…
Reference in New Issue