javascript - 在搜索输入字段中获取 db mysql 值并在下拉列表中进行修改
问题描述
我找不到我的问题的解决方案,因为对我来说它是高级编程水平。我有一个自定义搜索字段,但我需要在下拉菜单中“转换它”,以便在 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>
我希望我已经解释清楚了。有人能帮我吗?
解决方案
在控制台中,我找到了表单数据,搜索操作后生成的请求有效负载:
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');
我的直觉正确吗?
推荐阅读
- docusignapi - DocuSign 隐式代码授予访问令牌无法从浏览器 url 部分读取?
- c# - C# WinFrom ComboBox SelectedValueChanged 事件触发延迟
- javascript - 如何在 for 循环中添加数字一定次数并在 HTML 上显示
- python - 不满足条件的第一个值的索引 Numpy
- python - 为什么卸载python会保留安装目录
- android - 从启动活动移动到主活动时,意图产生空对象引用
- java - 休息模板。如何增加最大 tcp 连接数?
- c++ - 包含路径和 oistream 错误中的问题
- c# - WPF:当字体存储在 DLL 中时,如何在我的 EXE 中显示自定义字体
- python - 拆分字符串后怎么办?