[html-formfu] MultiForm current_form_number is 1 for form 1 and 2

Carl Franks fireartist at gmail.com
Tue Jan 5 12:05:19 GMT 2010


2010/1/4 Nick Spacek <nick.spacek at gmail.com>:
> Hi folks,
> I have a three step form where the current_form_number doesn't seem to be
> working correctly. I found another message from back in April about a
> similar problem, not sure if it's related.
> The form proceeds through the steps alright. I can submit the first step,
> the second step, etc. The problem I'm having is the current_form_number
> stays at 1 for the first two steps, and then changes to 2 in the third step.
> I am using this for some step-specific javascript.

current_form_number() is from the point of view of $form->process() -
not $form->render().

The reference to javascript makes me suspect that you're trying to use
current_form_number() for the form you're rendering.

Basically, when you render a MultiForm, and the current form-part has
no errors, and there are further forms-parts, render does:
    $self->next_form->render()
but this doesn't update current_form_number().

I think you'll need to use a similar logic to figure out which form
you're rendering - something like:

    $form_number = $multiform->current_form_number;
    if ( $multiform->current_form->submitted_and_valid ) {
        $form_number++;
    }

To explain in detail the numbers you describe above:

When you first load the MultiForm, it loads form 1, which hasn't yet
been submitted.
current_form_number() == 1
render() displays form 1

User submits form 1 with no errors.
current_form_number() == 1
params() returns data from form 1
render() displays form 2

User submits form 2 with no errors.
current_form_number() == 2
params() returns data from form 2
render() displays form 3

User submits form 3 with no errors - MultiForm is complete.
current_form_number() == 3
params() returns data from form 3
render() display form 3 - though why you'd want to do that, I don't know ;)

Hope this helps,
Carl



More information about the HTML-FormFu mailing list