├── LICENSE ├── README.md ├── app.js ├── index.html ├── jquery-2.1.4.js ├── preview.png ├── start_server.sh ├── style.css └── update_github_pages.sh /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Typeform I/O 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Sorry, Typeform I/O will be deprecated soon. Please visit https://developer.typeform.com/ to discover our new developer products 2 | 3 | 4 | # form-submit demo 5 | 6 | This is a demo of how you can use the `form-submit` event in Typeform I/O to create 7 | your own thank-you screens or send the user to a different page. 8 | 9 |  10 | 11 | ## Requirements 12 | 13 | * A browser 14 | 15 | ## Installing 16 | 17 | * Clone this project into your local computer 18 | 19 | ## Running 20 | 21 | * Run the server by executing `./start_server.sh` when inside the application directory 22 | * Visit http://localhost:8000 in your browser 23 | 24 | ## Where to get help 25 | 26 | * [Open up an issue](https://github.com/TypeformIO/form-submit-demo/issues/new) in this repository 27 | * In our official Slack channel ( [Signup](https://io1.typeform.com/to/sHP9NQ) ) 28 | * Send email to [support@typeform.io](mailto:support@typeform.io) 29 | 30 | ## Contributing 31 | 32 | If you want to contribute, just follow the general code style and code on! We 33 | love pull requests. 34 | 35 | If you're unsure if we're gonna merge it or not, create an issue before and we'll 36 | discuss it. 37 | 38 | ## License 39 | The MIT License (MIT) 40 | 41 | Copyright (c) 2015 Typeform 42 | 43 | Permission is hereby granted, free of charge, to any person obtaining a copy 44 | of this software and associated documentation files (the "Software"), to deal 45 | in the Software without restriction, including without limitation the rights 46 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 47 | copies of the Software, and to permit persons to whom the Software is 48 | furnished to do so, subject to the following conditions: 49 | 50 | The above copyright notice and this permission notice shall be included in 51 | all copies or substantial portions of the Software. 52 | 53 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 54 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 55 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 56 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 57 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 58 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 59 | THE SOFTWARE. 60 | 61 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | // _______ __ _____ ______ 2 | // |__ __| / _| |_ _| / / __ \ 3 | // | |_ _ _ __ ___| |_ ___ _ __ _ __ ___ | | / / | | | 4 | // | | | | | '_ \ / _ \ _/ _ \| '__| '_ ` _ \ | | / /| | | | 5 | // | | |_| | |_) | __/ || (_) | | | | | | | | _| |_ / / | |__| | 6 | // |_|\__, | .__/ \___|_| \___/|_| |_| |_| |_| |_____/_/ \____/ 7 | // __/ | | 8 | // |___/|_| 9 | // 10 | // form-submit event demo 11 | // 12 | // This demo application simply demonstrates how the form-submit in Typeform I/O 13 | // works. 14 | // 15 | // Run the `run-server.sh` script to start a server, navigate to http://localhost:8000 16 | // and try it out. 17 | // 18 | // The code is open source and available at https://github.com/typeformio/form-submit-demo 19 | 20 | 21 | 22 | // Which page to start on 23 | var first_page = "one"; 24 | 25 | ///////////////////// 26 | // Individual page actions 27 | ///////////////////// 28 | var pages = { 29 | "page_one": function() { 30 | fadeInStepsInPage('one', ['one', 'two', 'three', 'four']); 31 | // When the user clicks on the ready button, go to page two 32 | this.on('click', '#ready', function() { 33 | goToPage('two'); 34 | }); 35 | }, 36 | "page_two": function() { 37 | // Defer and focus the form for user input 38 | setTimeout(function() { 39 | $('#form').attr('src', 'https://forms.typeform.io/to/N8SfkWWXZG'); 40 | $('#form').focus(); 41 | }, 0); 42 | ///////////////////////////////////////////////////////////////////////////// 43 | // This is what you care about, the message event. It comes from the embedded 44 | // typeform and will have the originalEvent.data set to 'form-submit' if the 45 | // user submits the form. 46 | // If this event gets sent, we send the user to the third page and then change 47 | // the little debug event-status thing we have in the top-left 48 | $(window).on('message', function(ev) { 49 | if(ev.originalEvent.data === 'form-submit') { 50 | goToPage('three'); 51 | formEventHaveBeenSubmitted(); 52 | } 53 | }); 54 | }, 55 | "page_three": function() { 56 | fadeInStepsInPage('three', ['one', 'two', 'three', 'four']); 57 | }, 58 | } 59 | 60 | 61 | ///////////////////// 62 | // Application start 63 | ///////////////////// 64 | $(document).ready(function() { 65 | goToPage(first_page); 66 | }); 67 | 68 | 69 | ///////////////////// 70 | // Helper functions 71 | ///////////////////// 72 | 73 | // Hides all the pages 74 | function hideAllPages() { 75 | Object.keys(pages).forEach(function(page) { 76 | $('#' + page).hide(); 77 | }); 78 | } 79 | 80 | // Hides all the pages, show the one declared in page_name and then executes the 81 | // page function 82 | function goToPage(page_name) { 83 | hideAllPages(); 84 | $page = $('#page_' + page_name); 85 | $page.show(); 86 | pages['page_' + page_name].bind($page)(); 87 | } 88 | 89 | // Function to switch the status of the debug event-status 90 | function formEventHaveBeenSubmitted() { 91 | $('.event_not_yet').hide(); 92 | $('.event_submitted').fadeIn(); 93 | } 94 | 95 | // Function to animate the steps like a flashy intro 96 | function fadeInStepsInPage(page, steps) { 97 | if(steps.length > 0) { 98 | $('#page_' + page + ' .step_' + steps[0]).fadeIn(1000, function() { 99 | fadeInStepsInPage(page, steps.slice(1)); 100 | }); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 |