@@ -113,6 +113,8 @@ public function __construct( $attributes, $content = null, $form = null ) {
113113 'labelcolor ' => null ,
114114 'labelfontsize ' => null ,
115115 'fieldfontsize ' => null ,
116+ 'min ' => null ,
117+ 'max ' => null ,
116118 ),
117119 $ attributes ,
118120 'contact-field '
@@ -371,7 +373,18 @@ public function render() {
371373 $ field_value = Contact_Form_Plugin::strip_tags ( $ this ->value );
372374 $ field_label = Contact_Form_Plugin::strip_tags ( $ field_label );
373375
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 );
375388
376389 /**
377390 * Filter the HTML of the Contact Form.
@@ -928,12 +941,13 @@ public function render_date_field( $id, $label, $value, $class, $required, $requ
928941 * @param bool $required - if the field is marked as required.
929942 * @param string $required_field_text - the text in the required text field.
930943 * @param string $placeholder - the field placeholder content.
944+ * @param array $extra_attrs - Extra attributes used in number field, namely `min` and `max`.
931945 *
932946 * @return string HTML
933947 */
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 () ) {
935949 $ 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 );
937951 return $ field ;
938952 }
939953
@@ -1039,10 +1053,11 @@ class="below-label__label ' . ( $this->is_error() ? ' form-error' : '' ) . '"
10391053 * @param string $placeholder - the field placeholder content.
10401054 * @param bool $required - if the field is marked as required.
10411055 * @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.
10421057 *
10431058 * @return string HTML
10441059 */
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 () ) {
10461061 if ( ! $ this ->is_field_renderable ( $ type ) ) {
10471062 return null ;
10481063 }
@@ -1130,7 +1145,7 @@ public function render_field( $type, $id, $label, $value, $class, $placeholder,
11301145 $ field .= $ this ->render_consent_field ( $ id , $ field_class );
11311146 break ;
11321147 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 );
11341149 break ;
11351150 default : // text field
11361151 $ field .= $ this ->render_default_field ( $ id , $ label , $ value , $ field_class , $ required , $ required_field_text , $ field_placeholder , $ type );
0 commit comments