Search code examples
wordpresscontact-form-7

Save a Contact 7 Form to complete later


Is it possible for my users to fill a part of my form, save it, and then come back later and finish to fill the form entirely without losing all the data they add before ?

I used Contact 7 Form on Wordpress with S2Members.

Thank you.

Fabien


Solution

  • You could use a commercial plugin or do it yourself by saving the user input data in the browsers LocalStorage.

    LocalStorage allows Javascript websites and apps to store and access data from the browser with no expiration date.

    In order to save the users input data you could use a javascript library such as sisyphus-js for handling the browsers LocalStorage and attach the function to the form page, example:

    function saveFormData() {
        // The page where you have your form
        if ( is_page( 'page_for_your_form' ) ) {
            // Load the sisyphus-js for saving form data to local storage
            wp_enqueue_script( 'sisyphus-js', get_template_directory_uri() . '/js/path_to_sisyphus.js', array ( 'jquery' ), 1.1, true);
            ?>
                <script>
                    $( function() {
                        // You can also attach this function to a button via ie. onClick
                        $( "form" ).sisyphus(); 
                    } );
            </script>
            <?php
        }
    }
    add_action( 'wp_enqueue_scripts', 'saveFormData' );
    

    Code goes into your themes functions.php file