Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By wkolcz on
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
<?php$form =
Thanks!
Thanks! That seemed to work like a charm!