【问题标题】:Wordpress: display $current_user->display_name in form readonly input fieldWordpress:在表单只读输入字段中显示 $current_user->display_name
【发布时间】:2015-08-12 01:20:08
【问题描述】:

我想在只读的表单输入字段中显示 wordpress 登录的用户名(显示名称)。

我已经通过Function Reference/wp get current user但没有成功。

查找我尝试过的代码:

public static function getFormHTML($form) {
    global $wpdb, $display_name;
     get_currentuserinfo();

$html = '<form>';

/*-------Below line in displaying user display name----------------*/

$html .= '<input  name="currentusr" value="' . $current_user->display_name. '"  type= "text"  readonly />';

$html = '</form>';

我无法弄清楚我做错了什么..

请帮我解决...

提前致谢。

【问题讨论】:

    标签: php html wordpress


    【解决方案1】:

    不要使用readonly,而是尝试使用disabled 属性。例如:

    $html .= '<input name="currentusr" value="' . $current_user->display_name . '" type="text" disabled />';
    

    【讨论】:

    • 你从哪里得到你的$current_user对象?我在您的代码中没有看到它。
    • 嘿@henrywright,谢谢你提出的观点,我发现了错误,因为我犯了错误,不包括$current_user = wp_get_current_user();而不是get_currentuserinfo();
    • $current_user = wp_get_current_user() 是我所期待的,但在您的代码中的任何地方都看不到它:)
    猜你喜欢
    • 2019-07-20
    • 2014-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多