WordPress 表单自动填充
我正在尝试使用 WordPress 用户详细信息自动填写表单(当前使用联系表单 7)。
这是当前的代码:
<script type="text/javascript">
<?php
if (is_user_logged_in()){
global $current_user;
get_currentuserinfo(); ?>
document.getElementByName("your-name").value = "<?php $current_user->user_email ?>";
<?php
} ?>
</script>
我正在使用联系表单 7 插件,因此它是通过短代码调用的。
这段代码似乎没有发生任何事情,但我已经让它回显用户电子邮件,所以我认为这不是获取数据的问题。如果我必须打赌,用数据填写表格就会有问题。
我已经看到了一些用于联系表单 7 的自动填充插件,但我也想对其他表单(特别是重力表单)执行此操作,因此我需要一个通用的解决方案。
非常感谢任何帮助,谢谢。
I am trying to auto fill a form (currently using contact form 7) with wordpress user details.
this is the current code:
<script type="text/javascript">
<?php
if (is_user_logged_in()){
global $current_user;
get_currentuserinfo(); ?>
document.getElementByName("your-name").value = "<?php $current_user->user_email ?>";
<?php
} ?>
</script>
I am using the contact form 7 plugin so it is called via short code.
Nothing seems to happen with this code but I have gotten it to echo me the user email so I don't think that its a problem with fetching the data. If I had to bet, it would be a problem with filling the form with the data.
I have seen some auto fill plugins for contact form 7 but I also want to do this with other forms (specifically gravity forms) so I need a universal solution.
Any help is greatly appreciated, thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先确保您的联系表单具有类似于
的 HTML,然后尝试将代码放入 window.onload 事件中。您的 JavaScript 可能在页面完成加载所有内容(包括您的联系表单)之前运行。
像这样的事情:
编辑:根据下面的评论修复
First ensure that your contact form has HTML like
<input name='your-name' ...>
Then try and put your code inside a window.onload event. Your javascript is probably running before the page has finished loading everything including your contact form.Something like this:
Edit: Fixed as per comments below