-
Notifications
You must be signed in to change notification settings - Fork 0
/
minimumvalue.module
49 lines (44 loc) · 1.75 KB
/
minimumvalue.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/**
* Implementation of hook_webform_validation_validators().
*/
function minimumvalue_webform_validation_validators() {
return
array(
'validate_minimum_value' => array(
'name' => 'Validates Minimum Amount',
'description' => t( 'Verifies that the minimum amount is correct due to the selected frequency.' ),
'component_types' => array( 'int', 'number' ) )
);
}
/**
* Implementation of hook_webform_validation_validate().
*/
function minimumvalue_webform_validation_validate($validator_name, $items, $components, $rule ) {
// Definition of the minimum amounts
$min_amount = floatval(0.01);
// Errors
$error = 'Ha habido un error con la cantidad aportada introducida. Revísala, por favor. ¡Gracias!' ;
$errors = array();
if ( $items ) {
switch ( $validator_name ) {
case 'validate_minimum_value':
// Define one variable per field we want to check
$donativo = 0;
foreach ( $items as $key => $value ) {
$value_def = str_replace(",", ".", $value);
$donativo = floatval($value_def);
}
if( $donativo < $min_amount ){
// Mark the third box as an error, that is the other amount one
foreach( $items as $key => $value){
$errors[$key] = t( $error,
array( '%item' => $components[ $key ][ "name" ] ) );
}
}
return $errors;
break;
}
}
}
?>