I have a requirement which is as follows:

For a form I have to make the select time field.

One dropdown for selecting hours and one more for selecting minutes.

So I am displaying form using the drupal form system.

But the fields are getting displayed one below the other.

But the hours and minutes dropdowns are to be displayed side by side.

How to do this using drupal?

Thanks in advance!

Comments

Jeffrey04’s picture

I'm not sure whether CCK Date module suits ur requirements :D I'm new to drupal too :D
http://drupal.org/project/date

correct me if i am wrong

drupuser’s picture

I just want to display two form fields side by side. But with the default drupal form structure the form fields will be displayed one below the other. But I want to display them side by side.

Jeffrey04’s picture

sorry for not reading properly :D
Content Templates should be able to suit ur needs?
http://drupal.org/project/contemplate

drupuser’s picture

Is there some other way around to achieve this.

I have already build the entire form..

But i have to just display the hours and minutes fields side by side.

The code I implemented is as follows:

$form['hours'] = array(
'#type' => 'select',
'#title' => t("Hours"),
'#options' => array ("-1" => "Select", "1" => "1", "2" => "2", "3" => "3", "4" => "4", "5" => "5", "6" => "6", "7" => "7", "8" => "8", "9" => "9", "10" => "10", "11" => "11", "12" => "12"),
);

$form['minutes'] = array(
'#type' => 'select',
'#title' => t("Minutes"),
'#options' => array ("-1" => "Select", "1" => "1", "2" => "2", "3" => "3", "4" => "4", "5" => "5", "6" => "6", "7" => "7", "8" => "8", "9" => "9", "10" => "10", "11" => "11", "12" => "12"),
);

But as per drupal form interpretation, the hours and minutes fields will be displayed one below the other.

But I want the hours and minutes to be present side by side. How to modify the above code to meet the above requirements.

Thanks once again!

aina’s picture

Hi!

I also have the same problem.

Is there a solution to do this side by side display and to design a very customable form such as with dreamweaver using table?

Thanks,

Aina

Tmanagement’s picture

Can you not asign a CSS class to the hours and minutes or combine the output of those in CSS class in order to display it using inline?

drupuser’s picture

Can you include a sample code for what you are suggesting in this post so that I can implement the code right away. This is an urgent requirement for the project?

Tmanagement’s picture

Sorry I have not enough knowledge how to implement something with PHP.

All I can say is that when you want to design your PHP output you should add CSS tags to the code. For example:

drupuser’s picture

This is an issue how drupal declares form elements and displays them consequently. So CSS is not related to the issue here.

wheelercreek’s picture

This works in Drupal 5... notice the form element type is set to "date".

// format the default date if it exists
$edate = array();
$edate['year'] = 2008;
$edate['month'] = 6;
$edate['day'] = 12;

	
$form['event_date'] = array(
	'#type' => 'date',
	'#title' => t('Anticipated date of your event'),
	'#default_value' => $edate,
	'#required' => False
);
wheelercreek’s picture

Or you may need to modify the form structure in the module, something like this (from a credit card form I'm working on):

$form['details']['cc_month'] = array(
				'#type' => 'select',
				'#title' => t('Month'),
				'#default_value' => ($month ? $month : date('m')),
				'#options' => $months,
				'#description' => null,
				'#extra' => 0,
				'#multiple' => false,
				'#required' => true,
				'#prefix' => '<div id="expLabel">Expiration Date</div><div class="exp">',
				'#suffix' => '</div>',
			);

			$form['details']['cc_year'] = array(
				'#type' => 'select',
				'#title' => t('Year'),
				'#default_value' => ($year ? $year : date('Y')),
				'#options' => $years,
				'#description' => null,
				'#extra' => 0,
				'#multiple' => false,
				'#required' => true,
				'#prefix' => '<div class="exp"><div id="yr">',
				'#suffix' => '</div></div>',
			);

The added prefix and suffix will give you new div tags to work with in your CSS file. They wrap around the normal

tags. So you can then give them widths & float them if you want.

Hope that helps!

Alexandros78’s picture

Does anyone know if it is possible to add a prefix / suffix to an option?

What I have is this:

$form['agree'] = array(
'#prefix' => '

',
'#suffix' => '

',
'#title' => t('Do you agree to those terms?'),
'#required' => TRUE,
'#type' => 'radios',
'#options' => array('yes'=>t('Yes'), 'no'=>t('No'))
);

but I would like to do is add an aprefix-suffix pair to the "yes" option and to to the "no" option

Can this be done?