1

I have tried drupal_render,drupal_get_form etc for rendering the form,but the form is not being rendered. Is there any error in code or else what else should i add to the code so that it works.

function questionnaire_template_form($form, &$form_state, $question) {
 print_r("in template function");

 $form_build = unserialize($question->criteria_data);

 foreach ($form_build as $key => $value) {

  $options = ($form_build[$key]['1']);
   $list = explode("\n", $options);

   $list = array_map('trim', $list);

   $list = array_filter($list, 'strlen');

   foreach ($list as $key => $value) {

    $new = explode('|',$value);
    $new_key = reset($new);
    $new_value = end($new);
    $new_list = array($new_key => $new_value);
    dsm($new_list);
   }
dsm('next');

   $fb = explode("_",$key);
   $type =reset($fb);

  if($type == 'radio') {

    if($form_build[$key]['0']) {
      $form['radio_form'] = array(
        '#type' => 'radios',
        '#options' => $list,
      );
    }
  }
   elseif($type == 'checkbox') {
    if($form_build[$key]['0']) {
     $form['checkbox_form'] = array(
       '#type' => 'checkboxes',
       '#options' => $list,
      );
    }
   }
   elseif($type == 'selectlist') {
    if($form_build[$key]['0']) {
      $form['selectlist_form'] = array(
        '#type' => 'select',
        '#options' => $list,
        );
   }
  }

}
return $form;
}

Above code is my form.

<div>
<?php
//print_r($variables['entity']->qid);?></br><?php
print_r($variables['entity']->title);?></br><?php
print_r($variables['entity']->text);?></br><?php
?></br><?php
?></br><?php
if($variables['entity']->criteria) {
  ?><br/><?php
  $form_template = drupal_get_form('questionnaire_template_form' , $variables['entity']);
  print(drupal_render($form_template));

}
?></br><?php

print_r(l( t("Yes"), 'questionnaire/' . $variables['entity']->yes_quid));?></br><?php
print_r(l( t("No"), 'questionnaire/' . $variables['entity']->no_quid));?></br><?php

?>
</div>

And this is the template where I am rendering the form. I am getting the form if I dsm the form

  • Why do you not creating custom module for the same? – Jayendra Kainthola Oct 11 '13 at 6:38
  • This is custom module – neetu morwani Oct 11 '13 at 6:38
  • I ma not seeing anywhere, did you miss printing the rendered form? – arpitr Oct 11 '13 at 6:39
  • $form_template = drupal_get_form('questionnaire_template_form' , $variables['entity']); drupal_render($form_template); – neetu morwani Oct 11 '13 at 6:41
  • Are you attaching form with menu item or displaying in block and are you creating template for form or custom template? – Jayendra Kainthola Oct 11 '13 at 7:11
0

Drupal render will return the html

drupal_render(drupal_get_form('form_id'));    

you have to print the returned html as well.

print drupal_render(drupal_get_form('form_id'));

in your case

$form_template = drupal_get_form('questionnaire_template_form' , $variables['entity']); 
drupal_render($form_template);

change it to

$form_template = drupal_get_form('questionnaire_template_form' , $variables['entity']); 
print drupal_render($form_template);
  • I updated the code in question.Tried with print drupal_render($form_template); This too not working – neetu morwani Oct 11 '13 at 6:48
  • different approach, check if this link helps you – arpitr Oct 11 '13 at 7:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.