WP 联系表单 7:获取当前日期值以填充输入字段

发布于 2025-01-19 15:39:50 字数 1943 浏览 0 评论 0原文

在我的

到目前为止,我仅设法使用[hidden today_date _date]获得当前日期值,但我可以在电子邮件模板中使用,但这不是我需要的东西。

到目前-7-using-javasc">How do I change the value of text field in wordpress contact form 7 using javascript):

In contact form 7, i added the field ,希望JavaScript能够用DateTime值填写空引号。

With the plugin "WP Headers and Footers" i added the script

    var today = new Date();

    var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();

    var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();

    var dateTime = date+' '+time;

    document.getElementById("submissiondate").value = dateTime;

I tried the script in the header, in the body and in the footer.

结果始终是:一个空形式字段和一个JS错误:

uck offerate typeError:document.getElementById(...)为null

Can anybody help me with this?

编辑: Searching for help in this question i got the advice to add [hidden default:today_date _date id:submissiondate ] to the form and enter the js in the footer, like this:

    var today = new Date();
    var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
    var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
    var dateTime = date+' '+time;
    // this will set value for input with id submissiondate 
    jQuery('input#submissiondate').val(dateTime);   
    // check if value exists    
    var new_value = jQuery('#submissiondate').val();
    // display in console   
    console.log('current date time = ' + new_value);

Now the time value finds its way进入确认电子邮件,但仍未进入JetPack CRM自定义字段。 也许问题是这是一个隐藏的领域?我尝试添加[text默认:toven_date _date _date ID:提交]到表格中创建另一个字段,希望可以在JetPack CRM中用于自定义字段,但这都不起作用 - 自定义字段没有任何值。 有人知道如何使这个工作吗?

Using contact form 7 on my website, would like to retrieve the form submission date as an input value to use in "Jetpack CRM" for a custom field. I want to avoid that the user has to select the date with a date picker.

Until now i only managed to get the current date value with [hidden today_date _date] that i can use in email templates, but this is not the thing i need.

What i tried so far (after reading How do I change the value of text field in wordpress contact form 7 using javascript):

In contact form 7, i added the field <label> [text submission_date id:submissiondate ""] </label>, hoping that the javascript would fill out the empty quotes with the dateTime value.

With the plugin "WP Headers and Footers" i added the script

    var today = new Date();

    var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();

    var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();

    var dateTime = date+' '+time;

    document.getElementById("submissiondate").value = dateTime;

I tried the script in the header, in the body and in the footer.

The result is always: an empty form field and a js error:

Uncaught TypeError: document.getElementById(...) is null

Can anybody help me with this?

EDIT:
Searching for help in this question i got the advice to add [hidden default:today_date _date id:submissiondate ] to the form and enter the js in the footer, like this:

    var today = new Date();
    var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
    var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
    var dateTime = date+' '+time;
    // this will set value for input with id submissiondate 
    jQuery('input#submissiondate').val(dateTime);   
    // check if value exists    
    var new_value = jQuery('#submissiondate').val();
    // display in console   
    console.log('current date time = ' + new_value);

Now the time value finds its way into the confirmation email, but still not into the jetpack crm custom field.
Maybe the problem is that this is a hidden field? I tried alternatively to add [text default:today_date _date id:submissiondate ] to the form to create another field in the hope that this can be used for a custom field in jetpack crm but this does not work either – the custom field shows no value.
Does anybody know how to get this working?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

淡紫姑娘! 2025-01-26 15:39:50

找到解决方案 – 向 Santosh @ https://www.codeable.io/ 大声喊叫!
表单中的行 [text default:today_date _date id:submissiondate ] 是错误的 - 正确的行是 [textsubmissiondate id:submissiondate]

摘要:通过页面页脚中的javascript

    setInterval(add_date, 1000);    
    function add_date() {   
    var today = new Date();
    var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
    var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
    var dateTime = date+' '+time;
    // this will set value for input with id submissiondate   
    jQuery('input#submissiondate').val(dateTime); 
    // check if value exists    
    var new_value = jQuery('#submissiondate').val();
    // display in console   
    console.log('current date time = ' + new_value);
    }

和表单模板中的正确字段[textsubmissiondateid:submissiondate](用CSS隐藏在前端),我可以在jetpackcrm中使用字段值填充自定义字段,我也可以在确认电子邮件中使用它。 :-)

对于那些喜欢 2 位日期的人,可以像这样编辑脚本:

    setInterval(add_date, 1000);    
    function add_date() {   
    var today = new Date();
    currentMonth = today.getMonth()+1;
    currentMonth = ("0" + currentMonth).slice(-2);
    currentDay = today.getDate();
    currentDay = ("0" + currentDay).slice(-2);
    currentHour = today.getHours();
    currentHour = ("0" + currentHour).slice(-2);
    currentMinute = today.getMinutes();
    currentMinute = ("0" + currentMinute).slice(-2);
    currentSecond = today.getSeconds();
    currentSecond = ("0" + currentSecond).slice(-2);
    var date = today.getFullYear()+'-'+(currentMonth)+'-'+(currentDay);
    var time = (currentHour) + ":" + (currentMinute) + ":" + (currentSecond);
    var dateTime = date+' '+time;

    // this will set value for input with id buchung-versanddatum   
    jQuery('input#buchung-versanddatum').val(dateTime);

    // check if value exists    
    var new_value = jQuery('#buchung-versanddatum').val();

    // display in console   
    console.log('current date time = ' + new_value);
    }

SOLUTION FOUND – a big shoutout to Santosh @ https://www.codeable.io/!
The line [text default:today_date _date id:submissiondate ] in the form was wrong – the correct line is [text submissiondate id:submissiondate].

Summary: With the javascript in the page footer

    setInterval(add_date, 1000);    
    function add_date() {   
    var today = new Date();
    var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
    var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
    var dateTime = date+' '+time;
    // this will set value for input with id submissiondate   
    jQuery('input#submissiondate').val(dateTime); 
    // check if value exists    
    var new_value = jQuery('#submissiondate').val();
    // display in console   
    console.log('current date time = ' + new_value);
    }

and the correct field [text submissiondate id:submissiondate] in the form template (hidden on the front end with CSS), i can use the field value in jetpack crm to populate a custom field and i can use it in a confirmation email as well. :-)

For those who prefer 2-digit-dates, the script can be edited like this:

    setInterval(add_date, 1000);    
    function add_date() {   
    var today = new Date();
    currentMonth = today.getMonth()+1;
    currentMonth = ("0" + currentMonth).slice(-2);
    currentDay = today.getDate();
    currentDay = ("0" + currentDay).slice(-2);
    currentHour = today.getHours();
    currentHour = ("0" + currentHour).slice(-2);
    currentMinute = today.getMinutes();
    currentMinute = ("0" + currentMinute).slice(-2);
    currentSecond = today.getSeconds();
    currentSecond = ("0" + currentSecond).slice(-2);
    var date = today.getFullYear()+'-'+(currentMonth)+'-'+(currentDay);
    var time = (currentHour) + ":" + (currentMinute) + ":" + (currentSecond);
    var dateTime = date+' '+time;

    // this will set value for input with id buchung-versanddatum   
    jQuery('input#buchung-versanddatum').val(dateTime);

    // check if value exists    
    var new_value = jQuery('#buchung-versanddatum').val();

    // display in console   
    console.log('current date time = ' + new_value);
    }
薄凉少年不暖心 2025-01-26 15:39:50

查看您提到的 stackoverflow 页面,我注意到了这一点:

因此 JavaScript 代码不必放置在联系表单编辑器上。相反,它应该放置在联系表单短代码所在的页面上:下面是短代码的示例

https:// stackoverflow.com/a/50333080/11017029

也许您没有将 JavaScript 代码放在联系表单短代码所在的页面上。

Checking out the stackoverflow page you mentioned, I noticed this:

So the javascript code does not have to be placed on the contact form editor. Rather, it should be place on the page where the contact form short code is located: below is an example of the short code

https://stackoverflow.com/a/50333080/11017029

Maybe you didn't put your JavaScript code on the page where the contact form short code is located.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文