• Resolved bertelu

    (@bertelu)


    hi folks, 2 questions here

    i have a hidden datepicker field {date-1} in my form and i want that it will be autofilled with the today value. how this is possible?

    and second question related. can i extract the year from the previous field into another field?

    thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @bertelu

    I hope you’re well today!

    Datepicker field can be set to default value of “today” easily by simply setting “Default date” option in field’s “Settings” tab to “Today”.

    However, if you have that field set to be hidden via the field visibility conditions, such field will not be included in submission. Hiding field this way is meant to actually remove it form form/submission – to let you built more “dynamic” forms.

    So if you want that field to be hidden but actually submitted, you would need to remove visibility rule from it and instead hide it with CSS.

    As for “extracting year”, I’m not quite sure if I correctly understand. Do you mean that in one datepicker user sets the date and that year from that datepicker is copied to some other field?

    If yes – what kind of field: another datepicker or a text field? Could you explain the case a bit more, please?

    Best regards,
    Adam

    Thread Starter bertelu

    (@bertelu)

    thanks Adam got the point on hiding. indeed if the filed is visible the date is prefilled and submitted.

    about the year extraction, what i would like to do is the following:

    form populating the date field with “today” date.

    i need to have either:

    • or a text field that contains only the 4 digit of the year (2023)
    • or a way to fill a second custom hidden field where to put (automatically) the last day of the year

    as an example. today is the Dec 19th so the “date-1” field is containing 12-19-2023

    my goal is to have

    • or a text field that contain 2023
    • or a custom (or date) field that contain 12-31-2023

    hope it’s clear

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @bertelu,

    There isn’t any out of the box setting for such a feature, however, I’m checking this with our developer to see if there is any workaround that could be suggested.

    Will keep you posted once we get further feedback asap.

    Kind Regards,

    Nithin

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @bertelu,

    Could you please check and see whether the following helps or not?

    <?php
    
    add_filter( 'forminator_field_text_markup', function( $html, $field ) {
    		$field_id = 'text-1';
    
    		if ( ! empty( $field['element_id'] ) && $field_id ===  $field['element_id'] ) {
    
    			$html =date("Y"); 
    		}
    		
    		return $html;
    	},
    	10,
    	2
    );
    

    The above will fill the text-1 field with the current year ie 2023.

    You can update the following line to change the text field, ie if its text-2 field then it would change as:

    $field_id = 'text-2';

    Could you please check and see whether the above helps? You can apply the above code as a mu-plugins.

    Please check this link on how to implement the above code as a mu-plugins:
    https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins

    Best Regards,

    Nithin

    Thread Starter bertelu

    (@bertelu)

    great, it works.

    many thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘autofill date’ is closed to new replies.