在Drupal7-It';已添加但未渲染

在Drupal7-It';已添加但未渲染,drupal,drupal-7,Drupal,Drupal 7,我在尝试更改表单的呈现方式时遇到问题。然而,我试图让它像我发现的教程一样简单,但是即使template.php的hrfrontpage_form_alter函数中的$form项添加了div包装器,它也不会呈现它。为什么 在我的模块中: function rsearch_block_info() { $blocks['rsearch_form'] = array( 'info' => t('Search Recr

我在尝试更改表单的呈现方式时遇到问题。然而,我试图让它像我发现的教程一样简单,但是即使template.php的hrfrontpage_form_alter函数中的$form项添加了div包装器,它也不会呈现它。为什么

在我的模块中:

    function rsearch_block_info()
    {
            $blocks['rsearch_form'] = array(
                    'info' => t('Search Recruiters Front'),
            );

            return $blocks;
    }

    function rsearch_block_view($delta = '')
    {
            $block = array();

            switch($delta)  {
                    case 'rsearch_form' :
                            $block['content'] = drupal_get_form('rsearch_front');
                            break;
            }

            return $block;
    }
在my template.php中:

function hrfrontpage_form_alter(&$form, &$form_state, $form_id) {
        switch($form_id) {
                case 'rsearch_front' :
                        $form['divstart'] = array(
                                '#value' => '<div style="background-color:green;">',
                                '#weight' => -5
                        );
                        $form['divend'] = array(
                                '#value' => '</div>',
                                '#weight' => 5
                        );
                        break;
        }
}
函数hrfrontpage\u form\u alter(&$form,&$form\u state,$form\u id){
交换机($form_id){
案例“研究前”:
$form['divstart']=数组(
“#值”=>”,
“#重量”=>-5
);
$form['divend']=数组(
“#值”=>”,
“#重量”=>5
);
打破
}
}

好的,首先不能在一个表单元素中打开一个div,然后在另一个表单元素中关闭它,因为默认情况下每个表单元素都包装在一个div中

您需要做的是使用
“#前缀”和“#后缀”
字段元素

如果试图在多个字段周围放置div包装器,则需要将这些字段放在字段集中,并使用字段集中的前缀和后缀元素

简单案例:

 $form['my_field'] = array(
    '#type' => 'textfield',
    '#title' => 'search',
    '#prefix' => '<div style="background-color:green;">',
    '#suffix' => '</div>',
 );
$form['my_field']=数组(
“#键入”=>“文本字段”,
“#title”=>“search”,
“#前缀”=>”,
“#后缀”=>”,
);
复杂情况:

 unset($form['my_element']);

 $form['my_wrapper'] = array(
    '#type' => 'fieldset',
    '#prefix' => '<div style="background-color:green;">',
    '#suffix' => '</div>',
 );
 $form['my_wrapper']['my_field'] = array(  //Make sure your fields are children of the wrapper element!
    '#type' => 'textfield',
    '#title' => 'search',
 );
 $form['my_wrapper']['my_submit'] = array(  //Make sure your fields are children of the wrapper element!
    '#type' => 'submit',
    '#value' => 'submit',
 );
unset($form['myu元素]);
$form['my_wrapper']=数组(
“#类型”=>“字段集”,
“#前缀”=>”,
“#后缀”=>”,
);
$form['my\u wrapper']['my\u field']=array(//确保您的字段是wrapper元素的子元素!
“#键入”=>“文本字段”,
“#title”=>“search”,
);
$form['my\u wrapper']['my\u submit']=array(//确保您的字段是wrapper元素的子元素!
“#键入”=>“提交”,
“#值”=>“提交”,
);
查看表单API: