Render a form from an existing module We are just trying to gain a deeper understanding of Drupal forms and how to manipulate and render them as needed.

We have a module installed which allows uses to edit and create content through a form.  The module renders the form on its own edit/create page.  We would like to render the edit/create forms on a different page with other content.

Below are a few functions which we believe render the forms. (if not which function should we be looking for??)

/**
 * Page callback for creating a customer profile of a given type.
 */
function commerce_addressbook_profile_create($account, $profile_type) {
  // Add the breadcrumb for the form's location.
  commerce_addressbook_set_breadcrumb($account, $profile_type);

  $profile = commerce_customer_profile_new($profile_type, $account-&gt;uid);
  // The submit handler needs an indication that the profile was just added.
  // The regular is_new property gets unset after save is complete.
  $profile-&gt;_is_new = TRUE;
  module_load_include('inc', 'commerce_customer', 'includes/commerce_customer_profile.forms');
  return drupal_get_form('commerce_addressbook_customer_profile_form', $profile);
}

/**
 * Page callback for editing a customer profile.
 */
function commerce_addressbook_profile_options_edit($account, $customer_profile) {
  // Add the breadcrumb for the form's location.
  commerce_addressbook_set_breadcrumb($account, $customer_profile-&gt;type);

  // If the profile is referenced by an order, make sure it gets duplicated.
  $profile = clone($customer_profile);
  if (!commerce_customer_profile_can_delete($customer_profile)) {
    $profile-&gt;previous_id = $profile-&gt;profile_id;
    unset($profile-&gt;profile_id);
    unset($profile-&gt;revision_id);
    $profile-&gt;is_new = TRUE;
  }
  module_load_include('inc', 'commerce_customer', 'includes/commerce_customer_profile.forms');
  return drupal_get_form('commerce_addressbook_customer_profile_form', $profile);
}


What is the process for calling these functions (if they are the ones we are looking for) into a TPL page?







EASY TO READ COMMENTS:
I have added the follow to template.php within my theme directory

function THEME_preprocess_page(&amp;$variables){
    module_load_include('inc', 'commerce_addressbook', 'includes/commerce_addressbook.user');
    $variables['profile_form'] = commerce_addressbook_profile_options_edit($account, $customer_profile);
}


I have also included the following with a page tpl file.

&lt;?php print render($profile_form); ?&gt;


This results in the page returning a 500 error. (commenting out the variables line allows the page to load.)
You don't want to be putting that much PHP code into a tpl template file. Your menu item should have two parameters (user account, and profile type) and the page callback is specified as the desired function.

If you are doing this another way, you still need the user object and customer profile. In a preprocess function or in a custom page callback, you can create the form as a variable:

template.php:

// you can load a user account in various ways, ill assume this is behind a user path
$account = menu_get_object('user'); 
// you will need to verify this is the right function to use.
$customer_profile = commerce_customer_profile_load(profile_id_here);

$variables['profile_form'] = commerce_addressbook_profile_options_edit($account, $customer_profile);


in your tpl file:

&lt;?php print render($profile_form); ?&gt;


I am not familiar with the commerce_addressbook module, but there is a chance you'll need to include the file that defines those functions too, especially if they do not live in a .module file but live in a .inc file.

In which case, you'd need:

module_load_include('inc', 'commerce_addressbook', 'filepath/filename');
$variables['profile_form'] = commerce_addressbook_profile_options_edit($account, $customer_profile);