• Resolved beelinedigital

    (@beelinedigital)


    Is it possible to add a conditional lifespan. For example X amount of submissions are allowed, if a certain date is selected (using datepicker).

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

    (@wpmudevsupport14)

    Hi @beelinedigital,

    I hope you are keeping well, and thank you for reaching out to us.

    Unfortunately, this is now possible with Forminator out of the box. I have pinged our developers to check if we can provide an easy workaround for this and shall update you here if this is possible.

    Kind Regards,
    Nebu John

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @beelinedigital ,

    Please try this code:

    
    <?php
    add_filter(
    	'forminator_custom_form_submit_errors',
    	function( $submit_errors, $form_id, $field_data_array ) {
    		$forms_ids        = array( 11 );
    		$date_field_id    = 'date-1';
    		$has_date_error   = false;
    		$date_error_msg   = __( 'There is something wrong with the chosen date' );
    		$valid_start_date = '01/15/2022'; // Date format in example is M/d/Y.
    		$valid_end_date   = '01/25/2022'; // Date format in example is M/d/Y.
    
    		if ( ! in_array( $form_id, $forms_ids ) ) {
    			return $submit_errors;
    		}
    
    		$submitted_files = wp_list_pluck( $field_data_array, 'value', 'name' );
    
    		if ( empty( $submitted_files ) || ! in_array( $date_field_id, array_keys( $submitted_files ) ) ) {
    			$has_date_error = true;
    		} else {
    			$valid_start    = strtotime( $valid_start_date );
    			$valid_end      = strtotime( $valid_end_date );
    			$submitted_date = strtotime( $submitted_files[ $date_field_id ] );
    
    			if ( $valid_start > $submitted_date || $submitted_date > $valid_end ) {
    				$has_date_error = true;
    			}
    
    		}
    
    		if ( $has_date_error ) {
    			$submit_errors[][ $date_field_id ] = $date_error_msg;
    		}
    
    		return $submit_errors;
    	},
    	10,
    	3
    );

    You can use it as mu-plugin https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins

    kind regards,
    Kasia

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @beelinedigital ,

    We haven’t heard from you for a while now, so it looks like you don’t need our assistance anymore.

    Feel free to re-open this ticket if needed.

    Kind regards
    Kasia

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Conditional Lifespan’ is closed to new replies.