Commit 6cc75580 authored by jacintocapote's avatar jacintocapote Committed by jelles
Browse files

Issue #1666710 by jucallme, fastangel, mrfelton | stano.lacko: Fixed Client...

Issue #1666710 by jucallme, fastangel, mrfelton | stano.lacko: Fixed Client side validation for internal link wrong.
parent 17ee53de
......@@ -1309,6 +1309,30 @@
return ret;
}, jQuery.format('Please fill in at least one of the fields'));
// Support for Drupal urls.
jQuery.validator.addMethod("drupalURL", function(value, element) {
var result = false;
if (this.settings['name_event'] == 'onkeyup') {
return true;
}
if (jQuery.validator.methods.url.call(this, value, element)) {
return true;
}
jQuery.ajax({
'url': Drupal.settings.basePath + 'clientside_validation/drupalURL',
'type': "POST",
'data': {
'value': value
},
'dataType': 'json',
'async': false,
'success': function(res){
result = res;
}
});
return result.result;
}, jQuery.format('Please fill in a valid url'));
// Support for phone
jQuery.validator.addMethod("phone", function(value, element, param) {
var country_code = param;
......
......@@ -163,6 +163,14 @@ function clientside_validation_menu() {
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items['clientside_validation/drupalURL'] = array(
'title' => 'Clientside validation validate url callback',
'page callback' => '_clientside_validation_url_validation_callback',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
......@@ -1227,7 +1235,7 @@ function _clientside_validation_set_email($name, $title, &$js_rules, $message =
*/
function _clientside_validation_set_url($name, $title, &$js_rules, $message = '') {
$title = _clientside_validation_set_title($title);
$js_rules[$name]['url'] = TRUE;
$js_rules[$name]['drupalURL'] = TRUE;
$variables = array(
'message' => empty($message) ? 'The value in !title is not a valid url.' : $message,
'placeholders' => empty($message) ? array('!title' => $title) : array(),
......@@ -1584,3 +1592,50 @@ function clientside_validation_library_alter(&$libraries, $module) {
$libraries['jquery.form']['version'] = '3.09';
}
}
/**
* Check that a path is valid and accessible for internal and aliased paths, also if the path is an
* external url, it is validated according to RFC 2396.
*
* @param $path
* The path to check is valid.
*/
function _clientside_validation_url_validation_callback() {
$path = $_POST['value'];
$result = array();
$result['result'] = FALSE;
// Check if the url is valid according to RFC 2396.
if (filter_var($path, FILTER_VALIDATE_URL)) {
$result['result'] = TRUE;
}
// If we have an internal URL, strip out the query string and fragment
// before attempting to validate the URL.
if (!url_is_external($path)) {
$parsed_path = parse_url($path);
if (isset($parsed_path['query'])) {
$query = drupal_get_query_array($parsed_path['query']);
}
if (isset($parsed_path['fragment'])) {
$fragment = $parsed_path['fragment'];
}
if ($path != $parsed_path['path']) {
$path = $parsed_path['path'];
}
}
// Checks a path exists and the current user has access to it.
if (trim($path) && drupal_valid_path($path)) {
$result['result'] = TRUE;
}
else {
// Check if the aliased path, exists and the current user has access to it.
$lookup_path = drupal_lookup_path('source', $path);
if (drupal_valid_path($lookup_path)) {
$result['result'] = TRUE;
}
}
drupal_json_output($result);
}
......@@ -323,6 +323,7 @@ $.extend($.validator, {
var validator = $.data(this[0].form, "validator"),
eventType = "on" + event.type.replace(/^validate/, "");
if (validator.settings[eventType]) {
validator.settings['name_event'] = eventType;
validator.settings[eventType].call(validator, this[0], event);
}
}
......
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