I am trying to make a Contact form on a simple web site using latest Drupal 7.
This is what it should look exactly:

http://s18.postimage.org/hi11tr9qh/form.png

This is what I have achieved so far:

http://s10.postimage.org/sboemprmh/form_now.png

This is the core code I have used inside template.php of my custom template:

/**
 * Preproccess call to process the site contact form
 */
function mytheme_preprocess_contact_site_form(&$variables)
{
	//an example of setting up an extra variable, you can also put this directly in the template
	$variables['info'] = 'Please fill in the fields below to contact us';
	
	// Load additional html from a node
	$node = node_load(5);
	$node = node_view($node);
	$variables['info'] = $node['body'][0]['#markup'];//['#items'][0]['safe_value']
	//dpm($node);
	
	$variables['form']['name']['#title'] = '';
	$variables['form']['name']['#default_value'] = 'Your Name...';
	$variables['form']['mail']['#title'] = '';
	$variables['form']['mail']['#default_value'] = 'E-Mail';
	$variables['form']['message']['#title'] = '';
	$variables['form']['message']['#default_value'] = 'Your Message...';
	
	$options = array();
	$options['Purchases'] = 'Purchases';
	$options['Delivery'] = 'Delivery';
	$options['Urgent attention'] = 'Urgent attention';
	$variables['form']['subject']['#title'] = '';
	$variables['form']['subject']['#type'] = 'select';
	$variables['form']['subject']['#input'] = false;
    $variables['form']['subject']['#options'] = $options;
		
	//this is the contents of the form
	$variables['contact'] = drupal_render_children($variables['form']);
			
	//dpm($variables['form']);
}

function mytheme_form_required_marker($variables) {
	//dpm($variables);
	return '';
  // This is also used in the installer, pre-database setup.
  $t = get_t();
  $attributes = array(
    'class' => 'form-required',
    'title' => $t('This field is required.'),
  );
  return '<span' . drupal_attributes($attributes) . '>(required)</span>';
}

What forced me to post this here, is that this code already supposed to do 2 things which it somehow obviously does not:

- make "subject" field be a select box
- input default values specified

So far I have several questions:

- Is my code correct to achieve the above 2 goals in particular?
- Can I remove asterisks just for this form, keeping them for user login?
- Can I embed "onclick" javascript events directly into form fields html and thus have full control over form generation?
- If someone would suggest me to use Webform module instead, would it allow me to make the form looking exactly like on the first image?

Thanks for the attention.
Eugene

Edit: Images links are fixed.

Comments

webxtor’s picture

I have found some problems in my code and will update with the results some later.