我已经编程添加了一个“标记”元素到Drupal表单。当它在页面上呈现时,该元素将出现在提交按钮的包装中。 说明:应该出现在'field_school_name_value'元素和'distance'元素之间。我已经设定了每个元素的权重,希望这会强制布局是正确的,但似乎没有帮助。我究竟做错了什么?如何在“submit”元素的包装中呈现Drupal表单“标记”元素?
<?php
function abq_misc_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'views_exposed_form') {
$state_select = array(
'#attributes' => array(
'style' => 'width:10em;',
),
'#default_value' => 'All',
'#multiple' => FALSE,
'#options' => array_merge(array('All' => 'State'), location_get_provinces()),
'#title' => NULL,
'#type' => 'select',
'#weight' => 0,
);
$form['province'] = $state_select;
$school = &$form['field_school_name_value'];
$school['#attributes'] = array(
'size' => 15,
);
$school['#weight'] = 1;
// THIS GUY
$form['divider'] = array(
'#type' => 'item',
'#markup' => '<div>–or–</div>',
'#weight' => 2,
);
$form['distance']['#weight'] = 3;
$search_distance = &$form['distance']['search_distance'];
$search_distance['#attributes'] = array(
'placeholder' => 'miles',
'size' => '5',
);
$search_distance['#prefix'] = 'Within';
$search_distance['#suffix'] = 'of';
unset($search_distance['#title']);
$search_distance['#weight'] = 0;
$postal_code = &$form['distance']['postal_code'];
unset($postal_code['#title']);
$postal_code['#attributes'] = array(
'placeholder' => 'Zip Code',
'size' => '5',
);
$postal_code['#weight'] = 1;
hide($form['distance']['search_units']);
$form['submit']['#weight'] = 4;
}
}
对不起,我的原始问题还不清楚。我希望它出现在'field_school_name_value'元素和'distance'元素之间。似乎如果我在这两者的权重之间进行权衡,它应该可行......但事实并非如此。 – Xaq
@Xaq:不用担心,我已经更新了上面的答案应该有所帮助。 – Clive
我实施了这两个建议,但我仍然存在的问题。我需要将分隔线与其他表单元素放在同一水平线上,因为它需要水平居中在其他元素的上下两对之间({州和学校}和{距离和提交}。将分隔线作为前缀将其放在元素之前,但仍然在包装内,然后它的中心位置与它前缀的元素的宽度相同,这比整个表单的宽度要短。 – Xaq