Commit 7380304f authored by nkoth's avatar nkoth

[ENH] New Jquery validation to receive message to be shown when validation fails

parent d3f68b59
......@@ -1320,6 +1320,7 @@ installer/schema/20100429_newsletter_pages_tiki.sql -text
installer/schema/20100429_payment_user_fields_tiki.sql -text
installer/schema/20100507_flash_banner_tiki.php -text
installer/schema/20100519_actionlog_tiki.sql -text
installer/schema/20100525_tracker_validation_message_tiki.sql -text
installer/schema/20100525_tracker_validation_tiki.sql -text
installer/schema/99999999_image_plugins_kill_tiki.php -text
installer/schema/index.php -text
......
......@@ -2194,6 +2194,7 @@ CREATE TABLE `tiki_tracker_fields` (
`descriptionIsParsed` char(1) default 'n',
`validation` varchar(255) default '',
`validationParam` varchar(255) default '',
`validationMessage` varchar(255) default '',
PRIMARY KEY (`fieldId`),
INDEX `trackerId` (`trackerId`)
) ENGINE=MyISAM AUTO_INCREMENT=1 ;
......
#2010-05-25 nkoth
ALTER TABLE tiki_tracker_fields ADD COLUMN `validationMessage` varchar(255) default '';
......@@ -2429,7 +2429,7 @@ class TrackerLib extends TikiLib
}
function replace_tracker_field($trackerId, $fieldId, $name, $type, $isMain, $isSearchable, $isTblVisible, $isPublic, $isHidden, $isMandatory, $position, $options, $description='',$isMultilingual='', $itemChoices=null, $errorMsg='', $visibleBy=null, $editableBy=null, $descriptionIsParsed='n', $validation='', $validationParam='') {
function replace_tracker_field($trackerId, $fieldId, $name, $type, $isMain, $isSearchable, $isTblVisible, $isPublic, $isHidden, $isMandatory, $position, $options, $description='',$isMultilingual='', $itemChoices=null, $errorMsg='', $visibleBy=null, $editableBy=null, $descriptionIsParsed='n', $validation='', $validationParam='', $validationMessage='') {
// Serialize choosed items array (items of the tracker field to be displayed in the list proposed to the user)
if ( is_array($itemChoices) && count($itemChoices) > 0 && !empty($itemChoices[0]) ) {
$itemChoices = serialize($itemChoices);
......@@ -2460,19 +2460,19 @@ class TrackerLib extends TikiLib
$this->remove_field_images( $fieldId );
}
$query = "update `tiki_tracker_fields` set `name`=? ,`type`=?,`isMain`=?,`isSearchable`=?,
`isTblVisible`=?,`isPublic`=?,`isHidden`=?,`isMandatory`=?,`position`=?,`options`=?,`isMultilingual`=?, `description`=?, `itemChoices`=?, `errorMsg`=?, visibleBy=?, editableBy=?, `descriptionIsParsed`=?, `validation`=?, `validationParam`=? where `fieldId`=?";
$bindvars=array($name,$type,$isMain,$isSearchable,$isTblVisible,$isPublic,$isHidden,$isMandatory,(int)$position,$options,$isMultilingual,$description, $itemChoices, $errorMsg, $visibleBy, $editableBy, $descriptionIsParsed, $validation, $validationParam, (int) $fieldId);
`isTblVisible`=?,`isPublic`=?,`isHidden`=?,`isMandatory`=?,`position`=?,`options`=?,`isMultilingual`=?, `description`=?, `itemChoices`=?, `errorMsg`=?, visibleBy=?, editableBy=?, `descriptionIsParsed`=?, `validation`=?, `validationParam`=?, `validationMessage`=? where `fieldId`=?";
$bindvars=array($name,$type,$isMain,$isSearchable,$isTblVisible,$isPublic,$isHidden,$isMandatory,(int)$position,$options,$isMultilingual,$description, $itemChoices, $errorMsg, $visibleBy, $editableBy, $descriptionIsParsed, $validation, $validationParam, $validationMessage, (int) $fieldId);
} else {
$query = "insert into `tiki_tracker_fields` (`trackerId`,`name`,`type`,`isMain`,`isSearchable`,
`isTblVisible`, `isPublic`, `isHidden`, `isMandatory`, `position`, `options`, `fieldId`, `isMultilingual`, `description`, `itemChoices`, `errorMsg`, `visibleBy`, `editableBy`, `descriptionIsParsed`, `validation`, `validationParam`) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
$bindvars=array((int) $trackerId,$name,$type,$isMain,$isSearchable,$isTblVisible,$isPublic,$isHidden,$isMandatory,(int)$position,$options,(int) $fieldId,$isMultilingual, $description, $itemChoices, $errorMsg, $visibleBy, $editableBy, $descriptionIsParsed, $validation, $validationParam);
`isTblVisible`, `isPublic`, `isHidden`, `isMandatory`, `position`, `options`, `fieldId`, `isMultilingual`, `description`, `itemChoices`, `errorMsg`, `visibleBy`, `editableBy`, `descriptionIsParsed`, `validation`, `validationParam`, `validationMessage`) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
$bindvars=array((int) $trackerId,$name,$type,$isMain,$isSearchable,$isTblVisible,$isPublic,$isHidden,$isMandatory,(int)$position,$options,(int) $fieldId,$isMultilingual, $description, $itemChoices, $errorMsg, $visibleBy, $editableBy, $descriptionIsParsed, $validation, $validationParam, $validationMessage);
}
$result = $this->query($query, $bindvars);
} else {
$query = "insert into `tiki_tracker_fields`(`trackerId`,`name`,`type`,`isMain`,`isSearchable`,`isTblVisible`,`isPublic`,`isHidden`,`isMandatory`,`position`,`options`,`description`,`isMultilingual`, `itemChoices`, `errorMsg`, `visibleBy`, `editableBy`, `descriptionIsParsed`, `validation`, `validationParam`)
values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
$query = "insert into `tiki_tracker_fields`(`trackerId`,`name`,`type`,`isMain`,`isSearchable`,`isTblVisible`,`isPublic`,`isHidden`,`isMandatory`,`position`,`options`,`description`,`isMultilingual`, `itemChoices`, `errorMsg`, `visibleBy`, `editableBy`, `descriptionIsParsed`, `validation`, `validationParam`, `validationMessage`)
values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
$result = $this->query($query,array((int) $trackerId,$name,$type,$isMain,$isSearchable,$isTblVisible,$isPublic,$isHidden,$isMandatory,$position,$options,$description,$isMultilingual, $itemChoices, $errorMsg, $visibleBy, $editableBy, $descriptionIsParsed, $validation, $validationParam));
$result = $this->query($query,array((int) $trackerId,$name,$type,$isMain,$isSearchable,$isTblVisible,$isPublic,$isHidden,$isMandatory,$position,$options,$description,$isMultilingual, $itemChoices, $errorMsg, $visibleBy, $editableBy, $descriptionIsParsed, $validation, $validationParam, $validationMessage));
$fieldId = $this->getOne("select max(`fieldId`) from `tiki_tracker_fields` where `trackerId`=? and `name`=?",array((int) $trackerId,$name));
// Now add the field to all the existing items
$query = "select `itemId` from `tiki_tracker_items` where `trackerId`=?";
......
<?php
function validator_regex($input, $parameter = '') {
function validator_regex($input, $parameter = '', $message = '') {
$times = preg_match("/$parameter/", $input, $matches);
if (!$times || $matches[0] != $input) {
return false;
if ($message) {
return tra($message);
} else {
return false;
}
} else {
return true;
}
......
......@@ -22,13 +22,13 @@ class Validators
}
}
function validateInput( $validator, $parameter ) {
function validateInput( $validator, $parameter, $message = '' ) {
include_once('lib/validators/validator_' . $validator . '.php');
if (!function_exists("validator_$validator") || !isset($this->input)) {
return false;
}
$func_name = "validator_$validator";
$result = $func_name($this->input, $parameter);
$result = $func_name($this->input, $parameter, $message);
return $result;
}
......@@ -57,6 +57,7 @@ class Validators
$validationjs .= 'data: { ';
$validationjs .= 'validator: "' .$field_value['validation'].'", ';
$validationjs .= 'parameter: "' .$field_value['validationParam'].'", ';
$validationjs .= 'message: "' .$field_value['validationMessage'].'", ';
$validationjs .= 'input: function() { ';
$validationjs .= 'return $jq("#'.$prefix.$field_value['fieldId'].'").val(); ';
$validationjs .= '} } } ';
......
......@@ -168,6 +168,7 @@
</select>
</td></tr>
<tr class="formcolor"><td>{tr}Validation parameter{/tr}:</td><td><input type="text" size="30" name="validationParam" value="{$validationParam}" /></td></tr>
<tr class="formcolor"><td>{tr}Validation error message{/tr}:</td><td><input type="text" size="40" name="validationMessage" value="{$validationMessage}" /></td></tr>
<tr class="formcolor"><td>{tr}Order{/tr}:</td><td><input type="text" size="5" name="position" value="{$position}" /></td></tr>
<tr class="formcolor"><td>{tr}Field is mandatory?{/tr}</td><td><input type="checkbox" name="isMandatory" {if $isMandatory eq 'y'}checked="checked"{/if} /></td></tr>
......
......@@ -103,6 +103,7 @@ $smarty->assign_by_ref('visibleBy', $info['visibleBy']);
$smarty->assign_by_ref('editableBy', $info['editableBy']);
$smarty->assign('validation', $info['validation']);
$smarty->assign('validationParam', $info['validationParam']);
$smarty->assign('validationMessage', $info['validationMessage']);
if (isset($_REQUEST["remove"]) and ($tracker_info['useRatings'] != 'y' or $info['name'] != 'Rating')) {
$access->check_authenticity();
$trklib->remove_tracker_field($_REQUEST["remove"], $_REQUEST["trackerId"]);
......@@ -183,7 +184,7 @@ function replace_tracker_from_request($tracker_info) {
$_REQUEST['itemChoices'] = '';
}
//$_REQUEST["name"] = str_replace(' ', '_', $_REQUEST["name"]);
$trklib->replace_tracker_field($_REQUEST["trackerId"], $_REQUEST["fieldId"], $_REQUEST["name"], $_REQUEST["type"], $isMain, $isSearchable, $isTblVisible, $isPublic, $isHidden, $isMandatory, $_REQUEST["position"], $_REQUEST["options"], $_REQUEST['description'], $isMultilingual, $_REQUEST["itemChoices"], $_REQUEST['errorMsg'], $_REQUEST['visibleBy'], $_REQUEST['editableBy'], $_REQUEST['descriptionIsParsed'], $_REQUEST['validation'], $_REQUEST['validationParam']);
$trklib->replace_tracker_field($_REQUEST["trackerId"], $_REQUEST["fieldId"], $_REQUEST["name"], $_REQUEST["type"], $isMain, $isSearchable, $isTblVisible, $isPublic, $isHidden, $isMandatory, $_REQUEST["position"], $_REQUEST["options"], $_REQUEST['description'], $isMultilingual, $_REQUEST["itemChoices"], $_REQUEST['errorMsg'], $_REQUEST['visibleBy'], $_REQUEST['editableBy'], $_REQUEST['descriptionIsParsed'], $_REQUEST['validation'], $_REQUEST['validationParam'], $_REQUEST['validationMessage']);
$logslib->add_log('admintrackerfields', 'changed or created tracker field ' . $_REQUEST["name"] . ' in tracker ' . $tracker_info['name']);
$smarty->assign('fieldId', 0);
$smarty->assign('name', '');
......@@ -205,6 +206,7 @@ function replace_tracker_from_request($tracker_info) {
$smarty->assign('position', $trklib->get_last_position($_REQUEST["trackerId"]) + 1);
$smarty->assign('validation', '');
$smarty->assign('validationParam', '');
$smarty->assign('validationMessage', '');
}
if (isset($_REQUEST['refresh']) && isset($_REQUEST['exportAll'])) {
$smarty->assign('export_all', 'y');
......
......@@ -26,7 +26,7 @@ if (!in_array($_REQUEST['validator'], $validatorslib->available)) {
}
$validatorslib->setInput($_REQUEST["input"]);
$result = $validatorslib->validateInput($_REQUEST["validator"], $_REQUEST["parameter"]);
$result = $validatorslib->validateInput($_REQUEST["validator"], $_REQUEST["parameter"], $_REQUEST["message"]);
header( 'Content-Type: application/json' );
echo json_encode( $result );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment