Question

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.

Was it helpful?

Solution

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>

Fiddle:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top