Title: setting date picker required doesn&#039;t work
Last modified: August 22, 2016

---

# setting date picker required doesn't work

 *  [BenMurphy](https://wordpress.org/support/users/benmurphy/)
 * (@benmurphy)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/setting-date-picker-required-doesnt-work/)
 * I’m having an issue whereby setting the datepicker as a required field doesn’t
   seem to work. The form can be submitted with the datepicker still left blank.
   Any ideas?
 * [https://wordpress.org/plugins/contact-form-7-datepicker/](https://wordpress.org/plugins/contact-form-7-datepicker/)

Viewing 15 replies - 1 through 15 (of 18 total)

1 [2](https://wordpress.org/support/topic/setting-date-picker-required-doesnt-work/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/setting-date-picker-required-doesnt-work/page/2/?output_format=md)

 *  [ravimane1991](https://wordpress.org/support/users/ravimane1991/)
 * (@ravimane1991)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/setting-date-picker-required-doesnt-work/#post-5856009)
 * same problem here ..plase help
 *  [inse71](https://wordpress.org/support/users/inse71/)
 * (@inse71)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/setting-date-picker-required-doesnt-work/#post-5856012)
 * I have te same matter, expexting solutions
 *  [ximrx](https://wordpress.org/support/users/ximrx/)
 * (@ximrx)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/setting-date-picker-required-doesnt-work/#post-5856026)
 * Date and Time fields are not becoming required with [date* and [time*. And forms
   are submitting successfully with empty date and time.
 *  [rogerbattersby](https://wordpress.org/support/users/rogerbattersby/)
 * (@rogerbattersby)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/setting-date-picker-required-doesnt-work/#post-5856037)
 * Same problem here.
 * I’m sure it was working previously, so I guess a recent CF7 update has broken
   this?
 *  [lapoguidi](https://wordpress.org/support/users/lapoguidi/)
 * (@lapoguidi)
 * [11 years ago](https://wordpress.org/support/topic/setting-date-picker-required-doesnt-work/#post-5856043)
 * 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.
 *  [makinmemrees](https://wordpress.org/support/users/makinmemrees/)
 * (@makinmemrees)
 * [10 years, 12 months ago](https://wordpress.org/support/topic/setting-date-picker-required-doesnt-work/#post-5856045)
 * Thanks lapoguidi that worked perfectly!
 *  [wzshop](https://wordpress.org/support/users/wzshop/)
 * (@wzshop)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/setting-date-picker-required-doesnt-work/#post-5856047)
 * Thank you!
 *  [victormontesdeo](https://wordpress.org/support/users/victormontesdeo/)
 * (@victormontesdeo)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/setting-date-picker-required-doesnt-work/#post-5856048)
 * GENIUS lapoguidi!!
 *  [hotelijer](https://wordpress.org/support/users/hotelijer/)
 * (@hotelijer)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/setting-date-picker-required-doesnt-work/#post-5856051)
 * 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.
 *  [Alfonso Catrón](https://wordpress.org/support/users/alfonso100/)
 * (@alfonso100)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/setting-date-picker-required-doesnt-work/#post-5856064)
 * thank you lapoguidi! it worked like a charm
 *  [kasynych](https://wordpress.org/support/users/kasynych/)
 * (@kasynych)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/setting-date-picker-required-doesnt-work/#post-5856066)
 * 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
 *  [darfil](https://wordpress.org/support/users/darfil/)
 * (@darfil)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/setting-date-picker-required-doesnt-work/#post-5856079)
 * this second version works for me! thank you a lot! 🙂
 *  [Ananth JP](https://wordpress.org/support/users/ananth-jp/)
 * (@ananth-jp)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/setting-date-picker-required-doesnt-work/#post-5856080)
 * second version works for me. Thanks very much [@kasynych](https://wordpress.org/support/users/kasynych/).
 *  [adibtp](https://wordpress.org/support/users/adibtp/)
 * (@adibtp)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/setting-date-picker-required-doesnt-work/#post-5856081)
 * It worked great with 1st option! Thanks a lot lapoguidi!
 *  [sixtyseven](https://wordpress.org/support/users/sixtyseven/)
 * (@sixtyseven)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/setting-date-picker-required-doesnt-work/#post-5856082)
 * 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)

1 [2](https://wordpress.org/support/topic/setting-date-picker-required-doesnt-work/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/setting-date-picker-required-doesnt-work/page/2/?output_format=md)

The topic ‘setting date picker required doesn't work’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/contact-form-7-datepicker.svg)
 * [Contact Form 7 Datepicker](https://wordpress.org/plugins/contact-form-7-datepicker/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/contact-form-7-datepicker/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/contact-form-7-datepicker/)
 * [Active Topics](https://wordpress.org/support/plugin/contact-form-7-datepicker/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contact-form-7-datepicker/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contact-form-7-datepicker/reviews/)

 * 18 replies
 * 19 participants
 * Last reply from: [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * Last activity: [10 years, 2 months ago](https://wordpress.org/support/topic/setting-date-picker-required-doesnt-work/page/2/#post-5856088)
 * Status: not resolved