Community & Support

backporting simple D6 module to D5 (hook_form_alter question)

Hi,

I've not done much D5 module development, but I need to backport a small D6 module I wrote to D5.

hook_form_alter() has changed. The D6 version has a $form_state variable passed to it that contains the current form state. I've used that to do a little processing and change the value of a webform redirect. Code below. My question is, what's the D5 equivalent of the form_state variable?

<?php
// $Id$

function mindutilities_form_alter(&$form, &$form_state, $form_id) {
        if (
$form_id == 'webform_client_form_16') {
               
$form['#submit'][] = 'change_giftaid_details';
        } elseif (
$form_id == 'webform_client_form_15') {
               
$form['#submit'][] = 'change_normal_details';
        }
        return
$form;
}

function
change_giftaid_details(&$form, &$form_state) {
       
$sid = $form_state['values']['details']['sid'];
       
$type_from_form = $form_state['values']['submitted_tree']['type'];
       
$type = urlencode( $type_from_form . $sid );
       
$how_much = urlencode( $form_state['values']['submitted_tree']['details_of_donation']['amount_of_donation'] );
       
$form_state['redirect'] = str_replace( '[AMOUNT]', $how_much, $form_state['redirect'] );
       
$form_state['redirect'] = str_replace( '[CODENUMBER]', $type, $form_state['redirect'] );
}
function
change_normal_details(&$form, &$form_state) {
       
$sid = $form_state['values']['details']['sid'];
       
$type_from_form = $form_state['values']['submitted_tree']['type'];
       
$type = urlencode( $type_from_form . $sid );
       
$how_much = urlencode( $form_state['values']['submitted_tree']['amount_of_donation'] );
       
$form_state['redirect'] = str_replace( '[AMOUNT]', $how_much, $form_state['redirect'] );
       
$form_state['redirect'] = str_replace( '[CODENUMBER]', $type, $form_state['redirect'] );
}
?>

Comments

I don't see that you are

I don't see that you are using $form_state in your hook_form_alter().

Full-time freelancer, always looking for work.
jaypan.com (my portfolio)

Indeed, but it gets used in

Indeed, but it gets used in the functions that are called..?

Yes, but it is not calling

Yes, but it is not calling the functions directly. It is just passing a callback function name to the form API which will then call the callback function.

I only did a small bit of Drupal 5 module development, so I can't give specifics, but it seems to me that $form_state should be passed to the functions defined in #submit.

Full-time freelancer, always looking for work.
jaypan.com (my portfolio)

I shall give that a try.

I shall give that a try. Thanks for your time.

I've done a little more

I've done a little more digging on this and it seems like this comment answers my question
http://drupal.org/node/134000#comment-1556764