7

i created a module. I created a form and implemented it on the page:

function tudakozo_menu() {

  $items['tudakozo'] = array(
    'title' => t('Tudakozo'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('tudakozo_nevszerint_form'),
    'access callback' => TRUE,
  );

  return $items;
}

I would like to have an another form on this

2 Answers 2

17

Instead of using drupal_get_form as the page callback, you can specify a custom callback and build the forms there. An implementation in Drupal 6 would look similar to the following:

function tudakozo_menu() {

  $items['tudakozo'] = array(
    'title' => t('Tudakozo'),
    'page callback' => 'tudakozo_page_callback',
    'access callback' => TRUE,
  );

  return $items;
}

function tudakozo_page_callback() {
  $output = '';

  // Render your two forms here.
  $output .= drupal_get_form('tudakozo_nevszerint_form');
  $output .= drupal_get_form('tudakozo_second_form');

  return $output;
}

The only difference in Drupal 7 would be working with a render array as opposed to a string in the custom page callback similar to the code below:

function tudakozo_page_callback() {
  $build = array();

  // Render your two forms here.
  $build['form_one'] = drupal_get_form('tudakozo_nevszerint_form');
  $build['form_two'] = drupal_get_form('tudakozo_second_form');

  return $build;
}
5
  • Thank you Chris for fast answer. I have an "arrayarray" feedback. What can i do with it?
    – chrispooh
    Jul 27, 2011 at 11:01
  • I am assuming by your answer that you are working with D7, so I added a D7 example to the answer above. The explanation is that most content in D7 is represented as render arrays, so you will be working with arrays as opposed to strings. Your arrays are getting typecast, which is why you see "array". Modifying the callback slightly should fix the issue. Jul 27, 2011 at 15:28
  • @Chris, How do I theme these two forms in a tpl file? stackoverflow.com/questions/23242295/…
    – Kalidasan
    Apr 23, 2014 at 11:12
  • 1
    Found one article drupalknowledge.blogspot.in/2013/02/…
    – Kalidasan
    Apr 24, 2014 at 9:43
  • @kalidasan : but it does not says how to add it to my tpl file ?? did you find any answer for this. i have similar question here - drupal.stackexchange.com/questions/125632/…
    – Hitesh
    Aug 4, 2014 at 13:59
0

Check here

4. Next step is to create a hook_theme() function to theame these forms.
function custom_salesforce_theme() {
  return array(
 // this template is containing theme style for update form
    'custom_salesforce_update_form' => array(
      'template' => 'theme/custom_salesforce_update_form',
      'render element' => 'form',
    ),
 // this template is containing theme style for login form
    'custom_salesforce_login_form' => array(
      'template' => 'theme/custom_salesforce_login_form',
      'render element' => 'form',
    ),
 // this template is containing theme style for both forms
    'custom_salesforce_login_and_update' => array(
      'template' => 'theme/custom_salesforce_login_and_update',
      'arguments' => array('combine_form' => NULL),
    ),
  );
}

Note- Don't forget to create three template files inside theme folder inside your module.
5. Next step to write template preprocessor functions to display individual fields in separate template files.
/**
 * Implements Template Preprocessor For User Login().
 */
function template_preprocess_custom_salesforce_login_form(&$variables) {
  $variables['rtc_registered_email'] = drupal_render($variables['form']['rtc_registered_email']);
  $variables['rtc_password'] = drupal_render($variables['form']['rtc_password']);
  $variables['rtc_submit_form'] = drupal_render_children($variables['form']);
}

Above code describes how you can add two forms.

Below here This is how you add it to tpl file

<?php
$form = drupal_get_form('user_register_form');
print drupal_render($form);
?>

Hope it helps :)

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