/ Published in: PHP
By using hook_form_alter, you can add your own callback functions to any Drupal form.
These functions will be called when Drupal validates the form and when Drupal submits it.
In example below, a module called 'simple_checkout' adds its own handlers to a form called 'ideal_payment_api_issuer_form'. That latter is generated by another module, but we can fill our own tables and run our own validation *in addition to those by the originating module*.
These functions will be called when Drupal validates the form and when Drupal submits it.
In example below, a module called 'simple_checkout' adds its own handlers to a form called 'ideal_payment_api_issuer_form'. That latter is generated by another module, but we can fill our own tables and run our own validation *in addition to those by the originating module*.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * Implementation of hook_form_alter(). */ function simple_checkout_form_alter($form_id, &$form) { switch($form_id) { case 'ideal_payment_api_issuer_form': // Add a submit handler. // NOTE: we do not override the #submit array, but ADD our own to the array. That way we do not break existing submit-handlers! // Add a validate handler. break; } } // ... A lot of code ... /** * Fapi callback added in form_alter: validates the orders to our orders table. * * @param $form_id * Description of param $form_id * @param $form_values * Description of param $form_values * * @return * Nothing. */ function simple_checkout_order_validate($form_id, &$form_values) { // @TODO: prepare $order and insert into our DB table. } /** * Fapi callback added in form_alter: submits the orders to our orders table. * * @param $form_id * Description of param $form_id * @param $form_values * Description of param $form_values * * @return * Nothing. */ function simple_checkout_order_submit($form_id, &$form_values) { // @TODO: prepare $order and insert into our DB table. }
URL: http://wizzlern.nl