0

使用下面的示例,我可以成功地在 Gravityforms 编辑器中填充一个下拉列表,其中包含存储在我的数据库表中的状态列表......

add_filter("gform_pre_render_3", populate_dropdown1); //5 is the GF Form ID
add_filter("gform_admin_pre_render_3", populate_dropdown1);

function populate_dropdown1($form){
global $wpdb; //Accessing WP Database (non-WP Table) use code below.
$results = $wpdb->get_results("SELECT btc_state_short from btc_state_list");

$choices = array();
$choices[] = array("text" => "Select a State", "value" => ""); //adding a array option with no value, this will make the user select and option.

foreach ($results as $result) {
$choices[] = array("text" => $result->btc_state_short, "value" => $result->btc_state_short);
}

foreach($form["fields"] as &$field){
if($field["id"] == 1){
$field["choices"] = $choices;
}
}

return $form;
}

这很好用,但只有在您单击“更新表单”后。当您最初创建下拉列表时,它具有标准字段...

First Choice
Second Choice
Third Choice

有没有办法在拖入后立即预先填充它?

4

1 回答 1

0

在 Gravity Forms 中,该问题已在最新版本的表单字段中得到解决。一旦您选择 DropDown 并在您的字段上生成它,现在就会有一个完整的通用下拉列表。在 Common 生成的字段(即 First Choice Second Choice Third Choice)下方有一个标题为“批量添加/预定义选择”的按钮......

只需单击该按钮并选择您希望自动填充的字段,它将填充。

希望有帮助。

EP 系统技术技术

使用 GravityForms 版本 1.8.17 | 通过火箭天才 |

于 2014-10-07T14:48:59.503 回答