Giter Club home page Giter Club logo

gfrom's Introduction

Gfrom (From Google Form)

Wrap Google Form in your website. Useful for collecting data from your users without a database, and if you hate country restrictions of the form services out there. Plus you can style it your on way.

Just create a form from your google account and copy the published URL. If you are using Google Apps, please read form options, make sure Require sign-in to view this form is unchecked.

Installation

Add this line to your application's Gemfile:

gem 'gfrom'

And then execute:

$ bundle

Or install it yourself as:

$ gem install gfrom

Usage

GOOGLE_FORM_URL = "https://docs.google.com/a/myorganization.com/spreadsheet/embeddedform?formkey=dGlXS0ZNWVVGYWZqMVhXUENvOXQtSnc6MQ&hl=en"
@myform = Gfrom.new(GOOGLE_FORM_URL)
# fields are stored in array of hashes
# @fields=[
#   {:element=>"input", :type=>"text", :name=>"entry.479273699", :value=>"", :class=>"ss-q-short", :id=>"entry_479273699", :label=>"First name\n\n*", :dir=>"auto", :"aria-required"=>"true"},
#   {:element=>"input", :type=>"text", :name=>"entry.372120214", :value=>"", :class=>"ss-q-short", :id=>"entry_372120214", :label=>"Last name\n\n*", :dir=>"auto", :"aria-required"=>"true"},
#   {:element=>"input", :type=>"text", :name=>"entry.1874514893", :value=>"", :class=>"ss-q-short", :id=>"entry_1874514893", :label=>"Middle name", :dir=>"auto"},
#   {:element=>"input", :type=>"radio", :label=>"Male", :name=>"entry.1593861918", :value=>"Male", :id=>"group_1593861918_1", :class=>"ss-q-radio", :"aria-label"=>"Male"},
#   {:element=>"input", :type=>"radio", :label=>"Female", :name=>"entry.1593861918", :value=>"Female", :id=>"group_1593861918_2", :class=>"ss-q-radio", :"aria-label"=>"Female"},
#   {:element=>"input", :type=>"checkbox", :label=>"Ruby", :name=>"entry.299194237[]", :value=>"Ruby", :id=>"group_299194237_1", :class=>"ss-q-checkbox"},
#   {:element=>"input", :type=>"checkbox", :label=>"PHP", :name=>"entry.299194237[]", :value=>"PHP", :id=>"group_299194237_2", :class=>"ss-q-checkbox"},
#   {:element=>"input", :type=>"checkbox", :label=>"Django", :name=>"entry.299194237[]", :value=>"Django", :id=>"group_299194237_3", :class=>"ss-q-checkbox"},
#   {:element=>"input", :type=>"checkbox", :label=>"Python", :name=>"entry.299194237[]", :value=>"Python", :id=>"group_299194237_4", :class=>"ss-q-checkbox"},
#   {:element=>"input", :type=>"hidden", :name=>"draftResponse", :value=>"[] "},
#   {:element=>"input", :type=>"hidden", :name=>"pageHistory", :value=>"0"}
# ]
puts @myform.fields
# submit the form data to Google will return a hash
result = @myform.submit(params)
# { :success => true, :message => "Thanks" }
# or false otherwise, and an error message, which would probably unsatisfied required fields

In haml:

- @myform.fields.each do |node|
  - if node[:type] != "hidden"
    .inputline
      - element = node.delete(:element)
      %label{:for => node[:id]}=node[:label] if node[:label]
      - if element == "input"
        %input{node}
      - if element == "textarea"
        %textarea{node}
  - else
    %input{node}

TODO

  • Retain form values on unsuccesful submit
  • Fields with error after submit
  • Warn or raise exception if form is disabled (Accepting Responses is unchecked)
  • Provide a sample template for rails app
  • Label for grouped form tags - checkbox and radio
  • Support for getting select form tag (use radio button for now)
  • Support for Authenticated forms (requires login to organization/google apps)
  • Supply an RDOC

Good to have

<%= f.send(field.type.to_sym, field.name) %>

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

gfrom's People

Contributors

mrclmrvn avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.