You can have more than one form in the same page; see what done by node_admin_content(), which uses the following code:
function node_admin_content($form_state) {
if (isset($form_state['values']['operation']) && $form_state['values']['operation'] == 'delete') {
return node_multiple_delete_confirm($form_state, array_filter($form_state['values']['nodes']));
}
$form = node_filter_form();
$form['#theme'] = 'node_filter_form';
$form['admin'] = node_admin_nodes();
return $form;
}
Leaving out the first IF-statement, the function is adding two different forms that have their own submission handlers.
The problem is with the form fields that are repeated twice. The following array structure would create problems when the form array is flattened, as there would be two "coupon" fields.
$form['first form']['coupon'] = array(
'#type' => 'textfield',
'#title' => t('Coupon'),
'#default_value' => variable_get('mymodule_coupon'),
'#size' => 60,
'#maxlength' => 128,
'#required' => TRUE,
);
$form['second form']['coupon'] = array(
'#type' => 'textfield',
'#title' => t('Coupon'),
'#default_value' => variable_get('mymodule_coupon'),
'#size' => 60,
'#maxlength' => 128,
'#required' => TRUE,
);
Without to see the code being used, I could think that using a page callback that calls drupal_get_form() is probably the easier way, in your case.
$output = drupal_get_form("form identifier") . drupal_get_form("form identifier");
I tried using the following code in Drupal 6.
module_load_include('inc', 'path', 'path.admin');
$output = drupal_get_form('path_admin_form') . drupal_get_form('path_admin_form');
The content of $output
for the two form was the following one (I removed the output for the single form fields).
<form action="/dr61/devel/php" accept-charset="UTF-8" method="post" id="path-admin-form-1">
<div><div class="form-item" id="edit-language-1-wrapper">
<input type="submit" name="op" id="edit-submit" value="Create new alias" class="form-submit" />
<input type="hidden" name="form_build_id" id="form-4eb9304baac34f292901ca23d925ff03" value="form-4eb9304baac34f292901ca23d925ff03" />
<input type="hidden" name="form_token" id="edit-path-admin-form-form-token" value="cd429a06b84e381eb82ef04cd5033eeb" />
<input type="hidden" name="form_id" id="edit-path-admin-form" value="path_admin_form" />
<form action="/dr61/devel/php" accept-charset="UTF-8" method="post" id="path-admin-form-1">
<div><div class="form-item" id="edit-language-1-wrapper">
<input type="submit" name="op" id="edit-submit-1" value="Create new alias" class="form-submit" />
<input type="hidden" name="form_build_id" id="form-fb363c7ca6d88f71d98e86f8a69b0379" value="form-fb363c7ca6d88f71d98e86f8a69b0379" />
<input type="hidden" name="form_token" id="edit-path-admin-form-form-token-1" value="cd429a06b84e381eb82ef04cd5033eeb" />
<input type="hidden" name="form_id" id="edit-path-admin-form-1" value="path_admin_form" />
There is not a conflict between the HTML ID assigned to the same form field, and the value for "form_build_id" (or "form_token") is different in the two forms.
The implementation of hook_form_alter()
used to alter the form should be able to understand in which case to alter the form, or both the forms would show the same fields.
From the point of view of the user experience, I am not sure that showing two different forms with their own submission buttons is the best way to do what you are trying to achieve.
I would think that using a form that shows different fields basing on the values set for other fields would be better. For example, the form could have a selector for the type of the coupon, and would shown different form fields basing on the coupon type selected.