Monday, February 21, 2011

Create an Online public survey form using Google Docs


Step 1 - Create the Google Form

The first step is to create a Google Form from within Google Docs.  You can use form template or survey template. I created a form template as follows:

Remember this address with gform?key, in future you need this address to edit your form

Step 2 - Share

Go to Google Docs, click the document you just created. Then Action->Share->Share setting
->anyone with this link can view, you can see the address for anyone to view in popup
https://spreadsheets.google.com/ccc?key=0An205fRvYTLAdDktY09KTTE3Q1FoNG9RNTJXakxuWkE&hl=en&authkey=CNjy6Rw
This is a spreadsheet and you may need to let others input in nice web form.

Step 3 -  Find the key for view and user enter data


Go to Google Docs, click the document you just created. View page  source and search formkey and you can find something  like this
"formkey":"dDktY09KTTE3Q1FoNG9RNTJXakxuWkE6MQ"
Your form address for user enter the data will be:
 
https://spreadsheets.google.com/viewform?formkey=dDktY09KTTE3Q1FoNG9RNTJXakxuWkE6MQ
 
When user enter data, you can see all entries  in Step 2 URL (Spreadsheet)
-------------------------------------------------------------------------------- 
Advanced: Submit data to a Google Form with PHP: 
http://www.brighthub.com/hubfolio/matthew-casperson/articles/55171.aspx
Source code:
<?php
    $formURL = "http://spreadsheets.google.com/formResponse?formkey=dDVuRGlwQjgxSWxxUHV3dFN2TW9NdWc6MA&amp;ifq";
  
    function buildMultipleChoice($group, $heading, $options)
    {
        echo '<div>' . $heading . '</div>';
        echo '<ul style="list-style-type: none;">';
      
        foreach ($options as $option)
        {
            echo '<li><input type="radio" name="entry.' . $group . '.group" value="' . $option . '">';
            echo $option;
            echo '</li>';
        }
      
        echo '</ul>';
    }
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>PHP Google Forms</title>
    </head>
    <body>
        <?php
            echo '<form action="' . $formURL . '" method="POST">';
          
            buildMultipleChoice(0, 'What is your favourite colour?', array('Red', 'Green', 'Blue'));   
            buildMultipleChoice(1, 'What is your favourite fruit?', array('Apple', 'Banana', 'Pear'));
          
            echo '<input type="submit" name="submit" value="Submit">';
            echo '</form>';  
        ?>
    </body>
</html>

No comments:

Post a Comment