Viewing 15 replies - 1 through 15 (of 18 total)
  • same problem here ..plase help

    I have te same matter, expexting solutions

    ximrx

    (@ximrx)

    Date and Time fields are not becoming required with [date* and [time*. And forms are submitting successfully with empty date and time.

    rogerbattersby

    (@rogerbattersby)

    Same problem here.

    I’m sure it was working previously, so I guess a recent CF7 update has broken this?

    Hi, I experienced the same problem, but I solved changing few rows of code in Contact Form 7 Datepicker plugin, using CF7 author informations in Contact Form 7 v4.1 beta pages.

    After I save a backup copy of the original code, in /wp-content/plugins/contact-form-7-datepicker/modules/datetime.php I changed starting from line 124:

    if ('datetime*' == $type && empty($value)) {
    	$result['valid'] = false;
    	$result['reason'][$name] = wpcf7_get_message('invalid_required');
    }
    if (! empty($value) && ! self::is_valid_date($value)) {
    	$result['valid'] = false;
    	$result['reason'][$name] = wpcf7_get_message('invalid_datetime');
    }

    in that way:

    if ('datetime*' == $type && empty($value)) {
    	$result['valid'] = false;
    	$result['reason'] = array($name => wpcf7_get_message('invalid_required'));
    }
    if (! empty($value) && ! self::is_valid_date($value)) {
    	$result['valid'] = false;
    	$result['reason'] = array($name => wpcf7_get_message('invalid_datetime'));
    }

    Then I changed also date.php (from line 119) and time.php (from line 119) files in that similar way.

    I hope this helps, also if it’s not a perfect solution because change the original code, anyway I’ll wait for plugin author to update this great plugin.

    Thanks lapoguidi that worked perfectly!

    Thank you!

    GENIUS lapoguidi!!

    I have tried to solve the prblem the way lapoguidi suggested but it doesn’t work. Any ideas? Im using version od CF7 datepicker 2.4.5. Thank you in advance.

    thank you lapoguidi! it worked like a charm

    In case if the code above does not work, then try to change same code:

    if ('datetime*' == $type && empty($value)) {
    	$result['valid'] = false;
    	$result['reason'][$name] = wpcf7_get_message('invalid_required');
    }
    if (! empty($value) && ! self::is_valid_date($value)) {
    	$result['valid'] = false;
    	$result['reason'][$name] = wpcf7_get_message('invalid_datetime');
    }

    to

    if ('datetime*' == $type && empty($value)) {
    	$result->invalidate($tag,wpcf7_get_message('invalid_required'));
    }
    if (! empty($value) && ! self::is_valid_date($value)) {
    	$result->invalidate($tag,wpcf7_get_message('invalid_datetime'));
    }

    That’s obviously for new version of wpcf7

    this second version works for me! thank you a lot! 🙂

    second version works for me. Thanks very much @kasynych.

    It worked great with 1st option! Thanks a lot lapoguidi!

    Second version works like a charm. Thank you.

    In case someone is interested in conditional loading of CSS/JS of this plugin, this is what I came up with. Open contact-form-7-datepicker.php and add this function to the class:

    function check_shortcode() {
    		$form_found = false;
    
    		 global $post, $wpdb;
    
    		 // determine whether this page contains "contact-form-7" shortcode
    		 if ( has_shortcode($post->post_content, 'contact-form-7') ) {
    			$form_found  = true;
    		 } else if ( isset($post->ID) ) {
    			$result = $wpdb->get_var( $wpdb->prepare(
    			  "SELECT count(*) FROM $wpdb->postmeta " .
    			  "WHERE post_id = %d and meta_value LIKE '%%contact-form-7%%'", $post->ID ) );
    			$form_found  = ! empty( $result );
    		 }
    
    		 return $form_found;
    	}

    After that, you can control the loading of css and js by modify the responsible functions like this:

    public static function enqueue_js() {
    		$regional = CF7_DateTimePicker::get_regional_match();
    		$proto = is_ssl() ? 'https' : 'http';
    
    		$form_found = self::check_shortcode();
    
    		if($form_found || is_admin()) {
    
    			if (! empty($regional )) {
    				wp_enqueue_script(
    					'jquery-ui-' . $regional,
    					$proto . '://ajax.googleapis.com/ajax/libs/jqueryui/' . self::JQUERYUI_VERSION . '/i18n/datepicker-' . $regional . '.min.js',
    					array('jquery-ui-datepicker'),
    					self::JQUERYUI_VERSION,
    					true
    				);
    
    				wp_enqueue_script(
    					'jquery-ui-timepicker-' . $regional,
    					plugins_url('js/jquery-ui-timepicker/i18n/jquery-ui-timepicker-' . $regional . '.js', __FILE__),
    					array('jquery-ui-timepicker'),
    					'',
    					true
    				);
    			}
    
    			wp_enqueue_script('jquery-ui-datepicker');
    
    			wp_enqueue_script(
    				'jquery-ui-timepicker',
    				plugins_url('js/jquery-ui-timepicker/jquery-ui-timepicker-addon.min.js', __FILE__),
    				array('jquery-ui-datepicker'),
    				'',
    				true
    			);
    
    			wp_enqueue_script('jquery-ui-slider');
    
    			wp_enqueue_script(
    				'jquery-ui-slider-access',
    				plugins_url('js/jquery-ui-sliderAccess.js', __FILE__),
    				array('jquery-ui-slider', 'jquery-ui-button'),
    				'',
    				true
    			);
    
    			wp_register_script(
    				'jquery-ui-effect-core',
    				plugins_url('js/jquery.ui.effect.min.js', __FILE__),
    				array('jquery-ui-datepicker'),
    				self::JQUERYUI_VERSION,
    				true
    			);
    
    			foreach (CF7_DateTimePicker::$effects as $effect) {
    				wp_register_script(
    					'jquery-ui-effect-' . $effect,
    					plugins_url('js/jquery.ui.effect-' . $effect . '.min.js', __FILE__),
    					array('jquery-ui-effect-core'),
    					self::JQUERYUI_VERSION,
    					true
    				);
    			}
    
    		}
    	}
    
    	public static function enqueue_css() {
    
    		$form_found = self::check_shortcode();
    
    		if($form_found === true) {
    			wp_enqueue_style(
    				'jquery-ui-theme',
    				self::get_theme_uri(),
    				'',
    				self::JQUERYUI_VERSION,
    				'all'
    			);
    
    			wp_enqueue_style(
    				'jquery-ui-timepicker',
    				plugins_url('js/jquery-ui-timepicker/jquery-ui-timepicker-addon.min.css', __FILE__)
    			);
    		}
    	}
Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘setting date picker required doesn't work’ is closed to new replies.