Hi All,

I have complex html code that I want to put inside form element of page generated by form api. Form api shows no way of directly including html string in it. One has to create each and every element individual and there are limited elements. The current html code I am including becomes part of page but outside form element.

Please help I am stacked.

Comments

nevets’s picture

You do not provide enough detail to give you a specific solution but there is the '#markup' element type that takes any html as the value and elements generally support both '#prefix' and '#postfix' that allows attaching html before/after the form element.

pniraj007’s picture

Thanks a lot it solved my problem.

BrianLewisDesign’s picture

use theme_form() to get the form tag to render correctly:

function mymodule_form($form, &$form_state) {
  ...
  $form['#theme'] = 'mymodule_theme';  
  return $form;
}

function theme_mymodule_theme($variables) {
  $form = $variables['form'];	
  $buildform = '<div>' . drupal_render($form['element1']) . '</div>';
  $buildform .= drupal_render($form['element2']);
  $buildform .= drupal_render($form['form_build_id']);
  $buildform .= drupal_render($form['form_id']);
  $buildform .= drupal_render($form['form_token']);
  $form['element']['#children'] = $buildform;
  $output = theme_form($form);
  return $output;	
}