duanfan8699 2015-08-14 11:06
浏览 32

需要在textfield中打印变量

Im working on a WordPress-site where a reservationform is installed. I want the name of the logged on user is the defaultvalue in the "name" textfield since only loggen on users can make reservations. The php-code which builds the form looks like this (originial):

// Contact details fieldset
'contact'   => array(
'legend'    => __( 'Contact Details', 'restaurant-reservations' ),
'fields'    => array(
        'name'      => array(
        'title'         => __( 'Firmenname', 'restaurant-reservations' ),
        'request_input' => empty( $request->name ) ? '***VALUE***' : $request->name,
        'callback'      => 'rtb_print_form_text_field',
        'required'      => true,
),

This continues with other value like Mail and Phonenumber.

I need to get the value from the $user_login - variable printed in the textfield. I tried entering the variable itself, declare it, extending a string and tried to execute php-code. But nothing of this works out.

Is there any other way for printing out the variable in a textfield?

Please dont mind asking futher questions as i cant explain it that detailed.

Greets

  • 写回答

1条回答 默认 最新

  • doutuo7815 2015-08-14 11:27
    关注

    Assuming you are using a user plugin you can just call the current users details and output the user name in the text field

     $current_user = wp_get_current_user();
    
    // Contact details fieldset
    'contact'   => array(
    'legend'    => __( 'Contact Details', 'restaurant-reservations' ),
    'fields'    => array(
        'name'      => array(
        'title'         => __( 'Firmenname', 'restaurant-reservations' ),
        'request_input' => $current_user->user_login,
        'callback'      => 'rtb_print_form_text_field',
        'required'      => true,
    ),
    

    That should do the trick

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度