Google Spreadsheets recently offered the ability to create a form that will collect customer information into the spreadsheet. This is great for people that don’t have access to storing data in a traditional database (which is our preferred solution). They offer you the code to either link to for this form, email the code (great for emailed surveys) as well as code to embed (via IFrame) the form in your existing web page.
If you’d prefer to have FULL control over the display of the form and control the formatting and manipulation of data with your server-side code here is a handy little guide on how to do this using PHP.
- Create Google Doc form with all the fields your form needs
- Save the form
- Email yourself a copy of the form
- Pull the necessary fields out of the email to generate the form
URL for curl to post to
Names of the various input fields
- Insert code below into PHP page
- Test solution
Things to note about the above PHP code (gasp!) are that you need to define the proper URL to the spreadsheet and the correct number and names of fields (see step 4 above) . The only one that might be a little odd is getRealIpAddr() method. This is defined elsewhere in the page’s code as follows:
Have fun folks! If you want to rip into my code and/or have suggestions on better PHP coding styles, please use the comment section below…