1

Here is an example of how I made my AHAH fields in my form:

A textfield:

$form['info']['number'] = array(
        '#type' => 'textfield',
        '#title' => 'Number of people',
        '#weight' => 3,
        '#required' => TRUE,
        '#maxlength' => 6,
        '#prefix' => '<div class="textfield" id="number">',
        '#parents' => array('info','number'),
        '#suffix' => '</div>',
        '#size' => 20,
        '#ahah' => array(
                'event' => 'blur',          
                'path' => ahah_helper_path(array('info','number')),
                'wrapper' => 'number',
                'method' => 'replace',
                'effect' => 'none',
                'progress' => array (
                        'message' => $form_state['storage']['info']['number'],
                ),
        ),
        '#default_value' => $number,
);

And a select field for time:

    $form['choices']['time'] = array(
        '#type' => 'select',
        '#prefix' => '<div class="select time" id="time">',
        '#suffix' => '</div>',
        '#options' => array (
                0 => 'What time do you want to go?',
                1 => '07.00',
                2 => '07.15',
                ..
                64 => '22.45',
                65 => '23.00',
        ),
        '#weight' => 10,
        '#parents' => array('choices','time'),
        '#ahah' => array(
            'path' => ahah_helper_path(array('choices','time')),
            'wrapper' => 'time',
            'effect' => 'none',
            'method' => 'replace',
            'progress' => array (
                        'message' => $form_state['storage']['choices']['time'],
                ),
            ),
        '#default_value' => $time,
);

The way my form works is that the person fills in the number of people on the trip, and then selects a time. These two fields will trigger a third field made like the textfield above, which displays a price I grabbed from the database. There are 6 possible trips, so in the total (another textfield) all 6 of those will be added together for the price.

Here's the thing: The way my logic is written above, I can see that my prices are being passed to the total. I can see them in the POST and in the JSON response. They are in fact there. BUT the form itself does not display the values! The $cost and $total fields are still 1, even though I can that the price is passing correctly in the code itself. What happened? Does this have to do with $form_state or something else? Any pointers would be greatly appreciated.

1
  • The way I solved this was to make a button called Update and a callback which rebuild the form with the latest $form_state['values'] values. Works a charm! In case anyone else wanted to know... – glitchen Feb 14 '12 at 15:25

Your Answer

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

Browse other questions tagged or ask your own question.