Hi All,

Can anyone tell me, how to build custom form with our own html codes..

Any help would be great!!

Thanks
Prasath

Comments

kanagasabai’s picture

If by 'html codes' you mean you want to theme your form page, then you could it by hook_theme().

/**
 * Implements hook_theme().
 */
function yourtheme_theme($existing, $type, $theme, $path) {
  $base = array(
    'render element' => 'form',
    'path' => drupal_get_path('theme', 'yourtheme') . '/templates/forms',
  );

  return array(
    'form_id' => $base + array(
      'template' => 'template-name',
    ),
  );
}

And you may find template suggestions handy in these type of situation, to get it add the following in settings.php,
$conf['theme_debug'] = TRUE;

bharat.kelotra’s picture

If you want to wrap around your custom divs or want to add custom classes or ids or any other custom attribute to your form elements you can use the #prefix, #suffix and/or #attributes
e.g.

$form['example_field'] = array(
  '#type' => 'text',
  '#title' => t('some title'),
  '#prefix' => '<div class="test">', //this will add your custom html tags as starting field wrapper
  '#suffix' => '</div>', //this will add your custom html tags as ending field wrapper
  '#attribute' => array(
  				'class' => array('class-one', 'class-two'),
  				'id' => 'test-id',
  				'placeholder' => 'this is field placeholder',
  			),
);

You can add more attrbitues to #attributes there is no limit on it.

kunjal_programmer’s picture

you can use below code to use HTML in your form.

$html = '<div id="fiber3">
        <div class="row"><h4 class="col-sm-6">1 GB</h4><p class="col-sm-6 text-right"><small></small></p></div>
        <div class="progress">
          <div class="progress-bar progress-bar-success" role="progressbar"><span></span></div>
        </div>
      </div>';

$form['display_html'] = array(
        '#type'
            => 'markup',
            '#markup'
                => $html,
);