Hi @abhishek0088
I hope you’re well today!
For values between 0 – 100 you could use slider for that instead of the number as it already has a “step” setting and aside from the look/use on front-end, it behaves the same as number (in submission, calculations, conditional logic etc).
The “number” field does not have a step setting currently so it would require a bit of additional custom code to achieve it.
Here is the code:
<?php
add_action( 'forminator_before_form_render', 'wpmudev_number_field_step_form', 10, 5 );
function wpmudev_number_field_step_form( $id, $form_type, $post_id, $form_fields, $form_settings ) {
if ( 123 == $id ) {
add_filter( 'forminator_field_number_markup', 'wpmudev_add_step_number_field', 10, 5 );
}
}
function wpmudev_add_step_number_field( $html, $id, $required, $placeholder, $value ) {
$field_id = 'number-1';
if ( strpos( $id, 'forminator-field-'.$field_id ) !== false ) {
$html = str_replace( 'name="'.$field_id.'"', 'name="'.$field_id.'" step="5"', $html );
}
return $html;
}
And here’s how to apply it to the site:
1. create an empty file with a .php extension (e.g. “forminator-number-step.php”) in the “/wp-content/mu-plugins” folder of your site’s WordPress install
2. copy and paste that code into it
3. make following adjustments in the code
a) in this line
if ( 123 == $id ) {
replace the 123 number with an ID of your form (form ID is the number you see in form’s shortcode)
b) in this line
$field_id = 'number-1';
adjust field ID if it’s different than number-1
c) and in this line
$html = str_replace( 'name="'.$field_id.'"', 'name="'.$field_id.'" step="5"', $html );
change 5 to the value of the step (following your example, it would be 100).
4. save the file.
Note: make sure to set the default value for the number field also, otherwise the first “step” may be just 1 instead of the set value. So if you want e.g. min value to be stoo and step of 100, then set step=100 in code, set min value in number field to 100 and set default value of the number field to 100 as well.
Best regards,
Adam