• Resolved alexzaragoza21

    (@alexzaragoza21)


    Hi Great Support Team,

    I am using number field in my form.

    I hope I can seek help with these two things I want to achieve.

    1. Is there a way that we can set the increase/increment of value by 10, 100 (or specific amount) when users click the up and down arrow icons–> https://snipboard.io/DubZ43.jpg

    2. Is there a way that the number field can show currency sign and the numbers are formatted like an amount value? I mean with the right comma and period. Like this–> https://snipboard.io/F9wgbm.jpg

    I hope you can guide me. Not a coder here but I can follow.

    Thank you so much in advance.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support Nebu John – WPMU DEV Support

    (@wpmudevsupport14)

    Hi @alexzaragoza21,

    Thank you for asking this question.

    1. Is there a way that we can set the increase/increment of value by 10, 100 (or specific amount) when users click the up and down arrow icons–> https://snipboard.io/DubZ43.jpg

    I am afraid, this is not possible with Forminator out of the box. However, I have pinged our developers to check if an easy workaround could be provided and we will update about the same here.

    2. Is there a way that the number field can show currency sign and the numbers are formatted like an amount value? I mean with the right comma and period. Like this–> https://snipboard.io/F9wgbm.jpg

    Forminator has a currency field that should serve the purpose, please find more details about the same here: https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#currency-field

    I hope that helps.

    Best Regards,
    Nebu John

    Plugin Support Nebu John – WPMU DEV Support

    (@wpmudevsupport14)

    Hi again,

    To set the increment of value by 10 or 100 on a number field, please try using the following code.

    add_action( 'after_setup_theme', 'wpmudev_fm_custom_required_fields_func', 100 );
    
    function wpmudev_fm_custom_required_fields_func() {
    	if ( defined('FORMINATOR_PRO') && class_exists( 'Forminator' )  ) {
    		class WPMUDEV_FMCSN{
    			public $your_form_ids = [991];
    			public $number_field_ids = [
    				// [number_field_id] => [step]
    				'number-1' => 10,
    				'number-2' => 100
    			];
    
    			private $should_custom;
    			public function __construct(){
    				add_filter( 'forminator_cform_render_fields', array( $this, 'should_custom_required_field' ), 10, 2 );
    				add_filter( 'forminator_field_number_markup', array( $this, 'custom_number_field' ), 10, 2 );
    			}
    
    			public function should_custom_required_field( $wrappers, $form_id ){
    				if( in_array( $form_id, $this->your_form_ids ) ){
    					$this->should_custom = 1;
    
    				}
    				return $wrappers;
    			}
    
    			public function custom_number_field( $html, $field_id ){
    				if( $this->should_custom ){
    					$field_id = str_replace('forminator-field-', '', $field_id );
    					if( isset( $this->number_field_ids[ $field_id ] ) ){
    						$html = str_replace('name=', 'step="'. esc_attr( $this->number_field_ids[ $field_id ] ) .'" name=', $html );
    					}
    				}
    				return $html;
    			}
    		}
    
    		$run = new WPMUDEV_FMCSN();
    	}
    }

    Please note, you need to change the form id and number field id with the corresponding one from your form. You can add the code using a mu-plugin, please find more details here: https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins

    I hope that helps, please feel free to get back to us if you need any further assistance.

    Best Regards,
    Nebu John

    Thread Starter alexzaragoza21

    (@alexzaragoza21)

    Hello @wpmudevsupport14,

    Thank you so much for this!

    I will try it and see if I can make it work.

    Yes, I missed that Currency field that you already have.

    I hope it’s not too much. But please grant me one last favor.

    Is it possible to apply this code to the increment of currency field as well?

    I mean, I feel that this increment is much better now for the currency field that you already have.

    Thank you so much. I look forward for your response. More power to your team! ??

    Plugin Support Nebu John – WPMU DEV Support

    (@wpmudevsupport14)

    Hi @alexzaragoza21,

    The following code should help,

    add_action( 'after_setup_theme', 'wpmudev_fm_custom_required_fields_func', 100 );
    
    function wpmudev_fm_custom_required_fields_func() {
    	if ( defined('FORMINATOR_PRO') && class_exists( 'Forminator' )  ) {
    		class WPMUDEV_FMCSN{
    			public $your_form_ids = [991];
    			public $number_field_ids = [
    				// [number_field_names] => [step]
    				'number-1' => 10,
    				'number-2' => 100
    			];
    
    			private $should_custom;
    			public function __construct(){
    				add_filter( 'forminator_cform_render_fields', array( $this, 'should_custom_required_field' ), 10, 2 );
    				add_filter( 'forminator_field_number_markup', array( $this, 'custom_number_field' ), 10, 2 );
    				add_filter( 'forminator_field_currency_markup', array( $this, 'custom_number_field' ), 10, 2 );
    			}
    
    			public function should_custom_required_field( $wrappers, $form_id ){
    				if( in_array( $form_id, $this->your_form_ids ) ){
    					$this->should_custom = 1;
    
    				}
    				return $wrappers;
    			}
    
    			public function custom_number_field( $html, $field_id ){
    				if( $this->should_custom ){
    					$field_id = str_replace('forminator-field-', '', $field_id );
    					if( isset( $this->number_field_ids[ $field_id ] ) ){
    						$html = str_replace('name=', 'step="'. esc_attr( $this->number_field_ids[ $field_id ] ) .'" name=', $html );
    					}
    				}
    				return $html;
    			}
    		}
    
    		$run = new WPMUDEV_FMCSN();
    	}
    }

    Note: You need to change the form ID and the currency field name in the above code to the corresponding one from your form.

    Best Regards,
    Nebu John

    Thread Starter alexzaragoza21

    (@alexzaragoza21)

    Hi, I tried you code for number field but its not working,

    1. Created mu-plugin directory
    2. Uploaded this custom code in that directory
    3. Changed the form id and field name id in the code

    https://snipboard.io/aw8qSi.jpg
    https://snipboard.io/ucNroC.jpg

    What did I miss? THank you so much.

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @alexzaragoza21

    It looks fine on your screenshots, I don’t see anything wrong there. I also tested the code on my end and it works as expected.

    The two reasons that would be most common for such issue would be that:

    1. either the form ID or fields IDs – or both – are incorrect
    2. or there’s a limit set on number field that is too small for set increase amount (like e.g. you set to increase by 100 in code but configured field to allow values up to 99 only).

    However, note please that the first code that my colleague shared will not work with currency fields. I would use the second one (the last one shared above) instead – and that’s the one I tested on my end.

    Still, you will need to make sure about form ID and fields IDs (the “number-1”, “number-2” and so on – they must match form names as you see them in form builder).

    You may also want to clear all caches on site/server/CDN – if there is any – after adding the code to the site.

    Kind regards,
    Adam

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @alexzaragoza21

    I hope you are doing well and safe!

    We haven’t heard from you in a while, I’ll mark this thread as resolved.

    Feel free to let us know if you have any additional questions or problems.

    Best Regards
    Patrick Freitas

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Number field Custom Data Output’ is closed to new replies.