【发布时间】:2014-04-11 12:44:36
【问题描述】:
我有这个表格:
function tax_assistant_form_alter(&$form, $form_state, $form_id) {
//questa funzione è usata per alterare la disposizione del form originale
//contenuto in un altro modulo (linkableobject)
if ($form_id == 'linkableobject_node_form') {
$vid=26;
$query=taxonomy_get_tree($vid);
//Creo funzione per array name vocabulary
foreach($query as $rec){
$form["prova"]= array(
'#type'=> 'select',
'#title'=> t($rec->name),
'#options'=>array(get_vid($vid)),
'#ajax' => array(
'callback'=>'get_synonyms',
'wrapper'=>'area_sinonimi',
'replace'=>'TRUE',
),
);
}
//form dei sinonimi
$form['sinonimi'] = array(
// '#type' => 'hidden',
'#title'=> t('Sinonimi'),
'#prefix' => '<div id="area_sinonimi">Qui andrebbero i sinonimi',
'#suffix' => '</div>',
);
}
并用 ajax 调用这个函数 get_synonyms
function get_synonyms() {
$form_build_id = $_POST['form_build_id'];
$form_state = array('submitted' => FALSE);
$form = form_get_cache($form_build_id, $form_state);
$output="";
$synonyms = '';
$vid=26;
$tid = $_POST['prova'];
$result = db_query('SELECT name FROM {taxonomy_term_synonym} where tid=:tid', array(':tid'=>$tid));
//print_r($result);
$voc = get_vocabolario($vid);
if ($tid > 0)
$synonyms .= "<b>Synonyms for $voc:</b></br>";
foreach ($result as $rec) {
$synonyms.= "<i>'" . $rec->name . "';</i> ";
$keywords[$rec->name] = $rec->name;
}
$form['sinonimi'] = array(
'#type' => 'item',
'#description' => t("In order to facilitate the cataloging of your learning object,
try to make use of these terms for its description"),
'#value' => $synonyms,
);
$synonyms.='</br>';
form_set_cache($_POST['form_id'], $form, $form_state);
$form = form_builder($_POST['form_id'], $form, $form_state);
$output.=drupal_render($form['sinonimi']);
drupal_json_encode(array('status' => TRUE, 'data' => $output));
exit;
}
但是给我这个错误Recoverable fatal error: Argument 1 passed to drupal_array_set_nested_value() must be of the type array, null given, called in /var/www/html/glorep/includes/form.inc on line 2532 and defined in drupal_array_set_nested_value() (line 6598 of /var/www/html/glorep/includes/common.inc)。
我认为问题是ajax,当有D6时我已经从D6升级了这个,但我可以理解如何修改,有人可以帮助我吗?
【问题讨论】: