1
votes

I am creating a custom module for a Drupal 7 site and I need to create a form, using the form hook, and then include it in a template in the custom module.

I created a simple form in my .module file:

function my_login_form($form, &$form_state) {
  $form['email_address'] = array(
    '#type' => 'textfield',
    '#attributes' => array('placeholder' => t('Email Address')),
  );
  $form['phone'] = array(
    '#type' => 'password',
    '#attributes' => array('placeholder' => t('Password')),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Login',
  );

  return $form;
}

In my hook_menu() I have a route created and the 'page callback' pointed to the function:

function my_login(){

  return theme('my_login_template');

}

In my hook_theme() function I have it pointed to the .tpl:

function my_theme(){
  return array(

    'my_login_template' => array(
      'template' => 'login',
    ),
  );
}

How do I get the my_login_form into the login.tpl.php file?

Thank you for any help you can give or any place you can point me to.

1

1 Answers

2
votes

You need to pass it to theme :

function my_login(){
  $form = drupal_get_form('my_login_form');
  return theme('my_login_template',  array('form' => render($form)));

}

Into your tpl :

<?php print $form; ?>

Clear cache theme