在Drupal中通过ajax将数据填充到selectbox时出现问题
我安装了Drupal6,在一种内容类型中添加了一些cck字段。添加了两个选择框字段。 我获取父选择框的选定值,并根据该选择使用Ajax将选项与下一个选择框字段相关联。(例如Country->State。当用户选择Country时,我希望将状态值传递到下一个选择框。) 但当我提交表格时,会出现以下错误: “检测到非法选择。请与网站管理员联系。” 我不知道为什么它在保存节点时不采用ajaxified select box值。 有人有解决办法吗。在Drupal中是否有处理此动态选择选项的解决方案在Drupal中通过ajax将数据填充到selectbox时出现问题,ajax,drupal,select,parent-child,Ajax,Drupal,Select,Parent Child,我安装了Drupal6,在一种内容类型中添加了一些cck字段。添加了两个选择框字段。 我获取父选择框的选定值,并根据该选择使用Ajax将选项与下一个选择框字段相关联。(例如Country->State。当用户选择Country时,我希望将状态值传递到下一个选择框。) 但当我提交表格时,会出现以下错误: “检测到非法选择。请与网站管理员联系。” 我不知道为什么它在保存节点时不采用ajaxified select box值。 有人有解决办法吗。在Drupal中是否有处理此动态选择选项的解决方案 提前
提前感谢。我正在开发drupal 7,这也是我的工作。下面是代码。希望这对你有帮助。我所做的是选择汽车型号汽车变型将改变和数据保存在表中 函数add\u offer\u form($form,$formstate){ $form['add\u offer\u new\u car\u model']=数组( //组合框,用于选择新车型
$form['add_offer_new_car_variant'] = array(
'#type' => 'select',
'#options' => array(),
// The prefix/suffix provide the div that we're replacing, named by #ajax['wrapper'] above.
'#prefix' => '<div id="replace_variant">',
'#suffix' => '</div>',
);
}
////////////////////////////////////////////////////////
/////////用于AJAX回调的函数
函数变量_回调($form,&$form_状态){
}仅供参考,我相信定位模块会帮您做到这一点
$form['add_offer_new_car_variant'] = array(
'#type' => 'select',
'#options' => array(),
// The prefix/suffix provide the div that we're replacing, named by #ajax['wrapper'] above.
'#prefix' => '<div id="replace_variant">',
'#suffix' => '</div>',
);
if (!empty($formstate['values']['add_offer_new_car_model'])) {
$model_id = $formstate['values']['add_offer_new_car_model'];
$rows = array();
$result = db_query("SELECT id, variant_name from {va_car_variant} where car_model_id in ($model_id,1) order by variant_name");
while ($data = $result->fetchObject()) {
$id = $data->id;
$rows[$id] = $data->variant_name;
}
$form['add_offer_new_car_variant']['#options'] = $rows;
}
return $form['add_offer_new_car_variant'];