我一直在尝试在drupal 7中编写一个自定义模块,其中包含一个表单,其中包含一组字段,其中包含更多' “字段集合”中的选项(不想使用模块,但要编写控件代码)。我试图找到一个很好的例子,但没有成功。任何人都可以建议如何进行? PLZ !!
提前致谢。
答案 0 :(得分:0)
$form['education']['languages'] = array(
'#type' => 'fieldset',
'#title' => t('Languages'),
'#prefix' => '<div id="div_languages-fieldset-wrapper">',
'#suffix' => '</div>',
);
for ($i = 0; $i < $form_state['language_num']; $i++)
{
$form['education']['languages'][$i]['labels'] = array(
'#prefix' => '<h1 id = "stu_form_label">',
'#type' => 'item',
'#title' => t('Form :'.($i+1)),
'#suffix' => '</h1>',
);
// Language Drop down box
$option_language = _get_language_mstr();
$form['education']['languages'][$i]['language'] = array(
'#prefix' => '<div class="container-inline bottom_space languages_drop_down">',
'#options' => $option_language,
'#type' => 'select',
'#title' => t('Language'),
'#suffix' => '</div>',
);
// Level Drop down box
$option_Level = _get_level_mstr();
$form['education']['languages'][$i]['level'] = array(
'#prefix' => '<div class="container-inline bottom_space languages_drop_down">',
'#options' => $option_Level,
'#type' => 'select',
'#title' => t('Level'),
'#suffix' => '</div>',
);
}
if ($form_state['language_num'] > 1)
{
$form['education']['languages']['remove_name'] = array(
'#type' => 'submit',
'#value' => t('Remove last language'),
'#limit_validation_errors' => array(),
'#submit' => array('remove_one_language'),
'#ajax' => array(
'callback' => 'add_more_callback_language',
'wrapper' => 'div_languages-fieldset-wrapper',
),
);
}
$form['education']['languages']['add_name'] = array(
'#type' => 'submit',
'#value' => t('Add language'),
'#limit_validation_errors' => array(),
'#submit' => array('add_one_language'),
'#ajax' => array(
'callback' => 'add_more_callback_language',
'wrapper' => 'div_languages-fieldset-wrapper',
),
);
function add_more_callback_language($form, $form_state) {
return $form['education']['languages'];
}`
试试这个方法
示例链接:URL
点击标签教育