├── google_form_serverless_2021.png ├── serverless.php ├── LICENSE ├── example.php ├── README.md └── form.php /google_form_serverless_2021.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calledit/google_form_javascript_css/HEAD/google_form_serverless_2021.png -------------------------------------------------------------------------------- /serverless.php: -------------------------------------------------------------------------------- 1 | 6 |
11 | 16 | 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 callesg 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 | -------------------------------------------------------------------------------- /example.php: -------------------------------------------------------------------------------- 1 | 9 | 28 | 53 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # google_form_javascript_css 2 | System to embed css and javascript in to a google form 3 | 4 | Allows adding custom stylesheats and custom javascript to 5 | a google form. 6 | 7 | ### This is useful for 8 | * hiding questions 9 | * capturing which browser the user is using 10 | * capturing how large the users screen is 11 | * capturing how long time the user took to fill out the form 12 | * try to stop users from submiting the form more than one time. 13 | * Setting time limts on the google form. 14 | * Customizing the look and style of the form. 15 | * Hiding or showing questions based on earlier answerd questions. 16 | * Adding tracking to google forms like google analytics. 17 | * Detecting when users fill out questions but dont submit the form. 18 | 19 | 20 | ## Usage 21 | Upload **form.php and example.php** to a webserver that supports php. 22 | 23 | **Edit example.php and change the "google form" url**, to the "google form" that you want to change styling on. 24 | 25 | Then you can add CSS and javascript to the example.php file. 26 | 27 | ```javascript 28 | //The library adds one javascript convience function called 29 | question_val( 30 | question /*(string) The exact name of the question*/, 31 | value /*(string or function) What you want the default value to be, can be a value or a function (that will be called when the question is loaded)*/ 32 | overwrite /*(bool) if we are to write over the question if the form loads with a saved answer*/ 33 | ); 34 | 35 | //The library also adds two global javascript variables Question_Index and Headers_Index which contain the dom elements of all questions and headers. 36 | ``` 37 | 38 | ## Example 39 | Showing some basic CSS styling, hiding questions and filling out some questions with infromation such as the userAgent 40 | 41 | ```php 42 | 50 | 69 | 88 | ``` 89 | -------------------------------------------------------------------------------- /form.php: -------------------------------------------------------------------------------- 1 | array()); 22 | //We force english otherwise the form forces us to use the server locations country 23 | $context['http']['header'] = "Accept-Language: en-US,en;q=0.8,aa;q=0.6\r\n"; 24 | $context['http']['header'] .= "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.6.1 Safari/605.1.15\r\n"; 25 | //Sumbmit the form to google 26 | if(count($_POST) > 0){ 27 | $context['http']['method'] = 'POST'; 28 | $context['http']['header'] .= "Content-Type: application/x-www-form-urlencoded\r\n"; 29 | $context['http']['content'] = http_build_query($_POST); 30 | } 31 | $context = stream_context_create($context); 32 | $output = file_get_contents($form_url, false, $context); 33 | 34 | //replace links to google so that the form stays of googles domains 35 | $types = array( 36 | 'action', 37 | 'href', 38 | 'HREF' 39 | ); 40 | foreach($types AS $tp){ 41 | $type = $tp; 42 | $pts = explode(' '.$type.'="https://docs.google.com/forms/', $output); 43 | if(count($pts) == 2){ 44 | break; 45 | } 46 | } 47 | if(count($pts) == 2){ 48 | $spts = explode('"', $pts[1]); 49 | $url = 'https://docs.google.com/forms/'.array_shift($spts); 50 | $output = $pts[0].' '.$type.'="?url='.rawurlencode($url).'"'.implode('"', $spts); 51 | } 52 | if(!isset($_GET['proxy'])){ 53 | ?> 54 | 79 | 87 | 143 | --------------------------------------------------------------------------------