【问题标题】:fetch db mysql value in search input field and modifying in dropdown在搜索输入字段中获取 db mysql 值并在下拉列表中进行修改
【发布时间】:2020-07-13 22:00:26
【问题描述】:

我找不到我的问题的解决方案,因为对我来说这是一个高级编程水平。 我有一个自定义搜索字段,但我需要在下拉菜单中“转换它”,以便在 mysql 中获取一些用户值,避免编写数百个选择选项。 这是我正在处理的注册表单字段

<tr class="user-luogo-wrap">
<th><label for="luogo">
            Luogo:  </label></th>
    <td><input type="text" name="luogo" id="luogo" value="Treviso" class="regular-text"></td>
    </tr>

用函数创建

function my_user_contactmethods( $user_contactmethods ){
$user_contactmethods['luogo'] = 'Luogo:';
return $user_contactmethods;
}
add_filter('user_contactmethods', 'my_user_contactmethods', 5);

这是我需要获取 'luogo' mysql 值并在下拉列表中修改它的字段

<div class="um-search-filter um-text-filter-type "> <input type="text" autocomplete="off" id="luogo" name="luogo" placeholder="Luogo" value="" class="um-form-field" aria-label="Luogo"></div>

我希望我已经解释清楚了。有人可以帮我吗?

【问题讨论】:

  • 也许你正在寻找类似phppot.com/jquery/…
  • 您好,谢谢,但我不需要自动完成,而是自动生成下拉搜索数据(从特定数据库值)
  • 我解释得更好,如何从特定的注册表单字段或个人资料表单字段(gettin' meta key,id)填充下拉列表。
  • 我认为自动完成的想法很好,但不明白,在我看来,该指南是为 php 专家准备的。我想修改它,但不知道SELECT FROM tbl_country WHERE country_name LIKE ? 以及如何在我的函数 php 中挂钩你的 2 php

标签: javascript php mysql database forms


【解决方案1】:

在控制台中我找到了表单数据,搜索操作后生成的请求负载: directory_id=3f9fc&page=1&search=&sorting=display_name&gmt_offset=8&post_refferer=61&nonce=f47827a450&luogo=boston&action=um_get_members

所以我想修改这个函数

function field_choices( $field ) {  
    // reset choices
    $field['luogo'] = array();   
    // get the textarea value from options page without any formatting
    $choices = get_field('my_select_values', 'option', false);
    // explode the value so that each line is a new array piece
    $choices = explode("\n", $choices);   
    // remove any unwanted white space
    $choices = array_map('trim', $choices);
    // loop through array and add to field 'choices'
    if( is_array($choices) ) {      
        foreach( $choices as $choice ) {           
            $field['luogo'][ $choice ] = $choice;           
        }       
    }   
    // return the field
    return $field;    
}
add_action('um_get_members', 'field_choices');

我的直觉正确吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-27
    • 1970-01-01
    • 1970-01-01
    • 2018-03-14
    相关资源
    最近更新 更多