@@ -113,6 +113,8 @@ public function __construct( $attributes, $content = null, $form = null ) {
113
113
'labelcolor ' => null ,
114
114
'labelfontsize ' => null ,
115
115
'fieldfontsize ' => null ,
116
+ 'min ' => null ,
117
+ 'max ' => null ,
116
118
),
117
119
$ attributes ,
118
120
'contact-field '
@@ -371,7 +373,18 @@ public function render() {
371
373
$ field_value = Contact_Form_Plugin::strip_tags ( $ this ->value );
372
374
$ field_label = Contact_Form_Plugin::strip_tags ( $ field_label );
373
375
374
- $ rendered_field = $ this ->render_field ( $ field_type , $ field_id , $ field_label , $ field_value , $ field_class , $ field_placeholder , $ field_required , $ field_required_text );
376
+ $ extra_attrs = array ();
377
+
378
+ if ( $ field_type === 'number ' ) {
379
+ if ( is_numeric ( $ this ->get_attribute ( 'min ' ) ) ) {
380
+ $ extra_attrs ['min ' ] = $ this ->get_attribute ( 'min ' );
381
+ }
382
+ if ( is_numeric ( $ this ->get_attribute ( 'max ' ) ) ) {
383
+ $ extra_attrs ['max ' ] = $ this ->get_attribute ( 'max ' );
384
+ }
385
+ }
386
+
387
+ $ rendered_field = $ this ->render_field ( $ field_type , $ field_id , $ field_label , $ field_value , $ field_class , $ field_placeholder , $ field_required , $ field_required_text , $ extra_attrs );
375
388
376
389
/**
377
390
* Filter the HTML of the Contact Form.
@@ -928,12 +941,13 @@ public function render_date_field( $id, $label, $value, $class, $required, $requ
928
941
* @param bool $required - if the field is marked as required.
929
942
* @param string $required_field_text - the text in the required text field.
930
943
* @param string $placeholder - the field placeholder content.
944
+ * @param array $extra_attrs - Extra attributes used in number field, namely `min` and `max`.
931
945
*
932
946
* @return string HTML
933
947
*/
934
- public function render_number_field ( $ id , $ label , $ value , $ class , $ required , $ required_field_text , $ placeholder ) {
948
+ public function render_number_field ( $ id , $ label , $ value , $ class , $ required , $ required_field_text , $ placeholder, $ extra_attrs = array () ) {
935
949
$ field = $ this ->render_label ( 'number ' , $ id , $ label , $ required , $ required_field_text );
936
- $ field .= $ this ->render_input_field ( 'number ' , $ id , $ value , $ class , $ placeholder , $ required );
950
+ $ field .= $ this ->render_input_field ( 'number ' , $ id , $ value , $ class , $ placeholder , $ required, $ extra_attrs );
937
951
return $ field ;
938
952
}
939
953
@@ -1039,10 +1053,11 @@ class="below-label__label ' . ( $this->is_error() ? ' form-error' : '' ) . '"
1039
1053
* @param string $placeholder - the field placeholder content.
1040
1054
* @param bool $required - if the field is marked as required.
1041
1055
* @param string $required_field_text - the text for a field marked as required.
1056
+ * @param array $extra_attrs - extra attributes to be passed to render functions.
1042
1057
*
1043
1058
* @return string HTML
1044
1059
*/
1045
- public function render_field ( $ type , $ id , $ label , $ value , $ class , $ placeholder , $ required , $ required_field_text ) {
1060
+ public function render_field ( $ type , $ id , $ label , $ value , $ class , $ placeholder , $ required , $ required_field_text, $ extra_attrs = array () ) {
1046
1061
if ( ! $ this ->is_field_renderable ( $ type ) ) {
1047
1062
return null ;
1048
1063
}
@@ -1130,7 +1145,7 @@ public function render_field( $type, $id, $label, $value, $class, $placeholder,
1130
1145
$ field .= $ this ->render_consent_field ( $ id , $ field_class );
1131
1146
break ;
1132
1147
case 'number ' :
1133
- $ field .= $ this ->render_number_field ( $ id , $ label , $ value , $ field_class , $ required , $ required_field_text , $ field_placeholder );
1148
+ $ field .= $ this ->render_number_field ( $ id , $ label , $ value , $ field_class , $ required , $ required_field_text , $ field_placeholder, $ extra_attrs );
1134
1149
break ;
1135
1150
default : // text field
1136
1151
$ field .= $ this ->render_default_field ( $ id , $ label , $ value , $ field_class , $ required , $ required_field_text , $ field_placeholder , $ type );
0 commit comments