Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

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

share|improve this question

2 Answers 2

up vote 13 down vote accepted

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;
}
share|improve this answer
    
Thank you Chris for fast answer. I have an "arrayarray" feedback. What can i do with it? –  chrispooh Jul 27 '11 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. –  Chris Pliakas Jul 27 '11 at 15:28
    
@Chris, How do I theme these two forms in a tpl file? stackoverflow.com/questions/23242295/… –  kalidasan Apr 23 at 11:12
1  
Found one article drupalknowledge.blogspot.in/2013/02/… –  kalidasan Apr 24 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 at 13:59

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 :)

share|improve this answer

protected by Community Mar 2 '12 at 14:35

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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