ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Multiple page form

March 17, 2008 5:23pm

Subscribe [3]
  • #1 / Mar 17, 2008 5:23pm

    rpolito

    6 posts

    Hi
    I have one long form that i would like to break up into 5 different forms on different pages. It is a questionnaire and I think it would be a better experience going through a series of “next” pages rather than having one long form. So i am using the FreeForm module. How would i pass the info on so that all data from the five pages goes into the database when the visitor clicks submit?

    Thanks

  • #2 / Mar 17, 2008 6:00pm

    Mr. Wilson

    131 posts

    I will describe the basics of one approach. Create a template for each page of your form. Enable PHP parsing on input in all but the first page. On pages 2+, you might fetch the previous page’s form data by placing this code inside your <form></form> tags:

    <?php
    // This array holds all the form field names from the previous page(s) that are valid:
    $valid_fields = array(
        'name',
        'address',
        'city',
        'state',
        'zip',
        'occupation'
        );
    foreach($_POST as $k=>$v)
    {
        // Only keep the fields we specified above
        if (in_array($k, $valid_fields))
            echo "<input type='hidden' name='{$k}' value='{$v}' />\n";
    }
    ?>

    Note that this code doesn’t do any validation of the values (i.e. it doesn’t check to make sure that “zip” is a 5- or 9-digit number). That’s a whole other bucket of enchiladas.

    On the last page, set up the Freeform tags as usual and place some variation of the above PHP code inside.

    Does that get you started?

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases