• Resolved pppalumni

    (@pppalumni)


    Hi, i have an issue with a user meta field.

    The form has a birthday field with dropdown and format Y-m-d.

    I have custom user meta field “birthday”. By Submitting forminator form I need to write the birthday into the custom user field. It needs to be this format YYYY-MM-DD (2001-02-01).

    I forminator I use the following to write the data into the user meta field:
    {date-1-year}-{date-1-month}-{date-1-day}

    The custom field received the value 2001-2-1. However the format 2001-02-01 is expected in order to further process the data.

    Is there any way to add these “leading zeros” in month and day field?

    Thanks for helping

    • This topic was modified 2 years, 7 months ago by pppalumni.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello @pppalumni,

    I hope you’re doing well today.

    I have replicated that with the dropdown date field, and there’s no option to add zeros, so we’ll be checking this further with the Second Line Support (SLS) team.

    Please note, that it may take longer for the SLS techs to check, depending on the current number of complex tasks.

    As a workaround for now, you can use the Calendar type instead of Dropdowns, and {date-1} macro. This way the leading zeros should be automatically added.

    Best Regards,
    Dmytro

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @pppalumni ,

    Please try the following code as mu-plugin:

    
    <?php
    
    add_filter( 'forminator_prepared_data', 'wpmudev_date_field_macro_fix', 10, 2 );
    function wpmudev_date_field_macro_fix( $prepared_data, $module_object ){
    	if ( $module_object->id != 1609 ) { // Please change the form ID.
    		return $prepared_data;
    	}
    
    	if ( ! empty( $prepared_data['date-1-month'] ) ) {
    		$prepared_data['date-1-month'] = sprintf( "%02d", $prepared_data['date-1-month'] );
    	}
    
        if ( ! empty( $prepared_data['date-1-day'] ) ) {
    		$prepared_data['date-1-day'] = sprintf( "%02d", $prepared_data['date-1-day'] );
    	}
    
    	return $prepared_data;
    }

    Please change Form ID 1609 to your form’s ID.

    See how to create and use mu-plugins https://premium.wpmudev.org/docs/getting-started/download-wpmu-dev-plugins-themes/#installing-mu-plugins
    Make sure to take a backup before making any changes to your site.

    kind regards,
    Kasia

    Thread Starter pppalumni

    (@pppalumni)

    Hi all, thanks for your replies! Sounds promising.
    I’ll look into these possibilities!
    Best pppalummni

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘User Meta Date Format’ is closed to new replies.