我正在使用其中一个预渲染过滤器填充 wordpress 重力表单。
我通常遵循他们的文档,并使用每次都有效的 foreach 循环动态填充 $items[] 。
但是这次我没有为 $items[] 数组动态地创建一个 php foreach 循环,而是手动将每个值输入到一个数组中。
请看下面...
add_filter("gform_pre_render", "populate_dropdown_bike_make");
add_filter("gform_admin_pre_render", "populate_dropdown_bike_make");
function populate_dropdown_bike_make($form){
if($form["id"] != 4)
return $form;
$items = array();
$items[] = array(
"text" => "", "value" => null,
"text" => "YAMASAKI", "value" => "YAMASAKI",
"text" => "YAMOTO", "value" => "YAMOTO",
"text" => "YEZDI", "value" => "YEZDI",
"text" => "YIBEN", "value" => "YIBEN",
"text" => "YIYING", "value" => "YIYING",
"text" => "YONGKANG", "value" => "YONGKANG",
"text" => "YONGWANG", "value" => "YONGWANG",
"text" => "ZEBRETTA", "value" => "ZEBRETTA",
"text" => "ZENNCO", "value" => "ZENNCO",
"text" => "ZEPII", "value" => "ZEPII",
"text" => "ZERO-MOTORCYCLES", "value" => "ZERO-MOTORCYCLES",
"text" => "ZEV", "value" => "ZEV",
"text" => "ZHEJIANG", "value" => "ZHEJIANG",
"text" => "ZHENHUA", "value" => "ZHENHUA",
"text" => "ZHIXI", "value" => "ZHIXI",
"text" => "ZHONGYU", "value" => "ZHONGYU",
"text" => "ZING", "value" => "ZING",
"text" => "ZIPPI", "value" => "ZIPPI",
"text" => "ZIPSTAR", "value" => "ZIPSTAR",
"text" => "ZONGSHEN", "value" => "ZONGSHEN",
"text" => "ZONTES", "value" => "ZONTES",
"text" => "ZUNDAPP", "value" => "ZUNDAPP"
);
foreach($form["fields"] as &$field)
if($field["id"] == 45){
$field["choices"] = $items;
}
return $form;
}
现在的问题是它只返回下拉列表中的最后一个选项ZUNDAPP。
谁能明白为什么会这样?
谢谢