1

I am building a custom module that adds a form to certain node types that allows the user to fill/save some additional information about the node.

I would like to have 2 buttons. 1 which saves the data entered (currently working) and another which posts the data to an external script.

I can get this working by creating two different forms and settings their #action's accordingly but I would like the form markup all in a single fieldset, is this possible?

2

You can have both buttons in the same form. Inside the form's #submit handler (or each button's separate #submit handler), based on which button has been used to submit the form, you can either save the data, or do a drupal_http_request() to execute the external script.

Your form would include buttons roughly like this:

'save' => array(
  '#type' => 'submit',
  '#value' => t('Save'),
  '#submit' => array('save_function_name'),
),
'process' => array(
  '#type' => 'submit,
  '#value' => t('Process'),
  '#submit' => array('process_function_name'),
)

Then, the two functions save_function_name() and process_function_name() would do the job.

  • Would drupal_http_request() allow me to actually open the page? I would like the user to be able to print this page also – Tim Aug 8 '11 at 6:55
  • Hm... Now I'm not quite sure how to do that. You could use drupal_goto() for redirection to a drupal path. To redirect your users to an external webpage you could use header('Location:'). But to submit a POST form, I can really only think of a separate form, which is where you are coming from... – Jan Tomka Aug 8 '11 at 22:43
1

You can acccomplish that by calling drupal_render() and passing it the fieldset and its children.

The twitter module does this for the Drupal 6 version. See the following usage example:

$add_account = array(
  '#type' => 'fieldset',
  '#title' => t('Add Twitter accounts'),
  '#weight' => 5,
  '#collapsible' => TRUE,
  '#collapsed' => FALSE,
  '#children' => '',
);

if (user_access('add authenticated twitter accounts')) {
  $add_account['#children'] .= drupal_get_form('twitter_auth_account_form');
}
if (twitter_connect()) {
  $add_account['#children'] .= drupal_get_form('twitter_non_auth_account_form');
}
$output .= drupal_render($add_account);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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