欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

How to put two form elements in a row using Drupal Form API? 表单元素 放两个元素在一行 表单元素浮动显示 有大用

shiping1 的头像

How to put two form elements in a row using Drupal Form API?


I am creating a form in Drupal 6 using form API.

I need to put a textfield and a select next to each other. they are for entering something like 'www.domainname.com' . www. is fixed. domainname section is given from user in a textfield and .com section is chosen from select element by user.

So they should be in a line. but as I see I can put these two form elements in a line, they are in their div container.

Would you help me? Thank you.



正确答案:  Suppose if there are 2 form elements(text-box), you could just add an css style float:left; to the first <div> element . This makes both the text-boxes to appear in the same line.

Drupal Form :

$form['first_name'] = array(
        '#type'     => 'textfield',
        '#default_value' => 'First Name',
        '#size'     => 18,
        '#id' => 'first_name',
        '#prefix' => '<div class="samelineDiv">',
        '#suffix' => '</div>',

);

Here I have used prefix and suffix form controls

CSS:

.samelineDiv{
    float:left;
}

Sample html output :

<div class="textbox">
    <div class="samelineDiv">
        <div id="first_name-wrapper" class="form-item">
            <input type="text" class="form-text" value="First Name" size="14" id="first_name" name="first_name" maxlength="128">
        </div>
    </div>
</div>
<div class="textbox">
    <div id="last_name-wrapper" class="form-item">
        <input type="text" class="form-text" value="Last Name" size="14" id="last_name" name="last_name" maxlength="128">
    </div>
</div>



来自  http://stackoverflow.com/questions/16402244/how-to-put-two-form-elements-in-a-row-using-drupal-form-api

普通分类: