Contact Form 7: Set default date to today

ぐ巨炮叔叔 提交于 2019-12-30 06:56:12

问题


How do I set the default date to today, using Contact Form 7?

The minimum date can be set easily with min:today. When you click on a datepicker you can choose dates from today.

But the default date (before picking) is not today's date. The date is displayed like 2016/mm/dd or whatever date format.


回答1:


Yes, I added a script

<script>
jQuery(function ($) {
   var now = new Date(); 
   var day = ("0" + now.getDate()).slice(-2);
   var month = ("0" + (now.getMonth() + 1)).slice(-2);
   var today = now.getFullYear()+"-"+(month)+"-"+(day);
  $('#datePicker').val(today);
$("#datePicker").attr("min", today);
});
</script>

And than call it in:

[date* your-date class:required id:datePicker] 



回答2:


I found:

$(function() {
var now = new Date(); 
   var day = ("0" + now.getDate()).slice(-2);
   var month = ("0" + (now.getMonth() + 1)).slice(-2);
   var today = now.getFullYear()+"-"+(month)+"-"+(day);
  $('#datePicker').val(today);
$("#datePicker").attr("min", today);
});

Also, Don't Forget to add the library at first:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

I have called it as:

[date* check-in min:today id:datePicker]



回答3:


You can use min:today without using JavaScript or Jquery functions, see: https://contactform7.com/date-field/

[date* check-in min:today]


来源:https://stackoverflow.com/questions/37893462/contact-form-7-set-default-date-to-today

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!