Best way to create multi-step form with data saved to user account for later updating?

If you are working on a custom theme, I believe it is easier to be done with a page template and WordPress’s wp_ajax function.

The form can be included in the page using <?php get_template_part('form','0f-50-question') ?>.

Here is the pseudo code for the form

<form id="quite-a-long-form" action="<?php echo admin_url('admin-ajax.php'); ?>" method="post" class="form" >
    $step = $_GET['step']
    if $step = 1
        //first section of question
        echo <label>
        echo <input>
        echo <label>
        echo <input>
    else if $step = 2
        //second section of question
        echo <label>
        echo <input>
        echo <label>
        echo <input>
    else if $step = 3
        //third section of question
        echo <label>
        echo <input>
        echo <label>
        echo <input>
    // just repeat for all sections
    endif
    <input type="Submit">
    <?php wp_nonce_field('input-answer','security-code-here'); ?>
    <input name="action" value="input-answer" type="hidden">
</form>

And for the php that will process the file

function process_add_transfer() {
    if ( empty($_POST) || !wp_verify_nonce('security-code-here','add_transfer') ) {
        echo 'You targeted the right function, but sorry, your nonce did not verify.';
        die();
    } else {
        // do your function here 
        wp_redirect($_POST['_wp_http_referer'].'?step='.$index_of_the_next step);
    }
}

Hope this help

Leave a Comment