WP 联系表单 7:获取当前日期值以填充输入字段
在我的
到目前为止,我仅设法使用[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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
找到解决方案 – 向 Santosh @ https://www.codeable.io/ 大声喊叫!
表单中的行
[text default:today_date _date id:submissiondate ]
是错误的 - 正确的行是[textsubmissiondate id:submissiondate]
。摘要:通过页面页脚中的javascript
和表单模板中的正确字段
[textsubmissiondateid:submissiondate]
(用CSS隐藏在前端),我可以在jetpackcrm中使用字段值填充自定义字段,我也可以在确认电子邮件中使用它。 :-)对于那些喜欢 2 位日期的人,可以像这样编辑脚本:
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
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:
查看您提到的 stackoverflow 页面,我注意到了这一点:
https:// stackoverflow.com/a/50333080/11017029
也许您没有将 JavaScript 代码放在联系表单短代码所在的页面上。
Checking out the stackoverflow page you mentioned, I noticed this:
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.