I am new to Drupal and created a small form in a module (lifestyle) that I wanted to render and include inside another module (ptracker). In the rendering module i have the code snippet:

$html .= '<div><span style="font-size:20px;">Weekly Lifestyle Question:</span> '.drupal_render(lifestyle_question_form()).'</div>';

When I attempt to submit, nothing happens. When I view the source code, I do not see the form elements wrapped around it. What did I do wrong? Thanks!

Here is the module with the form I want rendered.

function lifestyle_question_form($form, &$form_state){
	global $user;

	$q = db_query("SELECT qid, question FROM {lifestyle_questions} WHERE start_date <= :today AND end_date >= :today", 
			array(':today' => date('Y-m-d')));
	$results = $q->fetchObject(); 
		
		$active = array(0 => t('No'), 1 => t('Yes'));
		  
		  $form['lifestyle_info']['answer'] = array(
			'#type' => 'select',
			'#title' => t($results->question),
			'#options' => array(
			  0 => t('No'),
			  1 => t('Yes'),
					),
			'#default_value' => 0,
			'#prefix' => '<div class="container-inline">', 
    
		  );
			
		$form['qid'] = array(
			'#type'=>'hidden',
			'#value' => $results->qid,
			);
			
		$form['submit'] = array(
				'#type' => 'submit',
				'#value' => t('Submit'),
				//'#submit' => array('lifestyle_post_form_submit'),
				'#suffix' => '</div>',
			);
		
	return $form;
}

Comments

Jaypan’s picture

$form = drupal_get_form('lifestyle_question_form');
$rendered_form = render($form);
wkolcz’s picture

Thanks! That seemed to work like a charm!