background image
Eric's picture

This code snippet will should you how to add additional functionality to a system form when it's submitted. You can do this in Drupal 5.x using a form_alter hook to modify the submit handlers on the form object. In my example, I'll show you how to add your own function that will executed when the contact form is submitted.

<?php
function MYMODULE_form_alter($form_id, &$form) {
 
// check for the form ID you'd like to alter
 
if ($form_id == 'contact_mail_page') {
   
// modify the "#submit" form property by prepending another submit handler array
   
$form['#submit'] = array_merge(
      array(
'_MYMODULE_contant_mail_page_submit' => array()),
     
$form['#submit']
    );
  }
}
?>

Now, when the contact form is submitted, you're submit handler will be processed as well. You'll need to define a function with the same name.

<?php
function _MYMODULE_contant_mail_page_submit($form_id, $form_values) {
 
// do whatever you'd like here and it will be executed when the contact form is submitted
}
?>