【问题标题】:Auto fill text inputs with user meta - email使用用户元数据自动填充文本输入 - 电子邮件
【发布时间】:2015-06-25 01:27:20
【问题描述】:

我有一个未使用任何插件制作的表单,我正在寻找一种方法来查看用户是否已登录,获取他们的电子邮件地址,然后填写该字段:

<tr><td><span style='nowrap:nowrap;font-size:15px;font-family:Arial;width:200px;line-height: 22px;'>Email'</span><br><input type='text' maxlength='100' style='width:250px;' name='Email'></input></td></tr>

我会使用插件,但必须有办法不使用任何插件。而且由于表单不是使用插件制作的,CF7 动态文本扩展对我(但我认为)或重力表单不起作用。 提前致谢。

【问题讨论】:

    标签: wordpress forms input metadata


    【解决方案1】:

    获取当前获取电子邮件的 get_currentuserinfo 函数。

    检查代码。

    <?php   
     if ( is_user_logged_in() ) {
    
              global $current_user;
              get_currentuserinfo();
              $user_email =   $current_user->user_email;
    
        } else{
    
            $user_email =  " " ;
          }
            ?>
        <input type='text' maxlength='100' value="<?php echo $user_email ?>" style='width:250px;' name='Email'>
    

    【讨论】:

    • 我最终使用了 php 内联,这很糟糕吗? &lt;tr&gt;&lt;td&gt;&lt;span style='nowrap:nowrap;font-size:17px;font-family:Arial;width:200px;line-height: 22px;'&gt;Email&lt;span style='color:red;'&gt;*&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;input type='text' maxlength='100' style='width:250px;' name='Email' value=" &lt;?php if ( is_user_logged_in() ) { $current_user = wp_get_current_user(); $emuser = $current_user-&gt;user_email; echo $emuser; } ?&gt;"&gt;&lt;/input&gt;&lt;/td&gt;&lt;/tr&gt;
    猜你喜欢
    • 1970-01-01
    • 2012-07-28
    • 1970-01-01
    • 2020-11-11
    • 1970-01-01
    • 2012-04-01
    • 2021-01-30
    • 2016-11-21
    • 1970-01-01
    相关资源
    最近更新 更多