Skip to content

Commit 3a73d1a

Browse files
committed
gw-min-and-max-character-limits.php: Added support for validating list fields.
1 parent fb64324 commit 3a73d1a

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

gravity-forms/gw-min-and-max-character-limit.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Plugin URI: https://gravitywiz.com/require-minimum-character-limit-gravity-forms/
1010
* Description: Adds support for requiring a minimum and maximum number of characters for text-based Gravity Form fields.
1111
* Author: Gravity Wiz
12-
* Version: 1.2
12+
* Version: 1.3
1313
* Author URI: https://gravitywiz.com/
1414
*/
1515
class GW_Minimum_Characters {
@@ -34,6 +34,15 @@ public function __construct( $args = array() ) {
3434
'max_validation_message' => __( 'You may only enter %s characters.' ),
3535
) );
3636

37+
/**
38+
* @var int $form_id
39+
* @var int $field_id
40+
* @var int $min_chars
41+
* @var false|int $max_chars
42+
* @var false|string $validation_message
43+
* @var string $min_validation_message
44+
* @var string $max_validation_message
45+
*/
3746
// phpcs:ignore WordPress.PHP.DontExtract.extract_extract
3847
extract( $this->_args );
3948

@@ -56,6 +65,14 @@ public function validate_character_count( $result, $value, $form, $field ) {
5665
if ( count( explode( '.', $this->_args['field_id'] ) ) > 1 ) {
5766
$modifier = explode( '.', $this->_args['field_id'] )[1];
5867
$value = rgar( $value, $field->id . '.' . $modifier );
68+
} elseif ( $field->type === 'list' ) {
69+
foreach ( $value as $row_values ) {
70+
foreach ( $row_values as $row_value ) {
71+
$result = $this->validate_character_count( $result, $row_value, $form, $field );
72+
}
73+
}
74+
75+
return $result;
5976
} else {
6077
return $result;
6178
}

0 commit comments

Comments
 (0)