Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="container">
  <h1 class="text-center">
    【GAS】 スプレッドシートと連携したAjaxフォーム
  </h1>
  <hr />
  <form action="https://script.google.com/macros/s/AKfycbxI3xhvF7LPOwJJInnredfxkDfkNyDTvkqUSRIysNye3X2s8R4/exec" class="form-horizontal">
    <input name="SPREADSHEET_ID" type="hidden" value="179G_PAUfFupy5T1rN1WKadgdSnCzpYL8JU7FdEGd54k" /><input name="SHEET_NAME" type="hidden" value="フォームデータ" />
    <div class="form-group">
      <label class="col-md-2 control-label">メールアドレス</label>
      <div class="col-md-10">
        <input class="form-control" name="メールアドレス" placeholder="test@test.com" type="email" />
        <p class="help-block">
          メールアドレスを入力すると、そのアドレス宛に自動返信メールを送信します。<br />メールアドレスはスプレッドシートに登録されないので、安心してお試し下さい。自分のGmail(lab.snowsunny)に送信履歴が残りますが、その情報を何かに使用する事は有りません。<br />どうしても不安なら<a href="https://one-time.email">One-Time.Email</a>を使うのがおすすめです!HTMLメールとテキストメールの両方を同時に確認する事が出来ます。
        </p>
      </div>
    </div>
    <div class="form-group">
      <label class="col-md-2 control-label">Qiitaのユーザー名</label>
      <div class="col-md-10">
        <input class="form-control" name="Qiitaのユーザー名" placeholder="良ければQiitaのユーザー名を教えて下さーい" />
      </div>
    </div>
    <div class="form-group">
      <label class="col-md-2 control-label">一言コメント</label>
      <div class="col-md-10">
        <input class="form-control" name="一言コメント" placeholder="適当でOK。何かコメントを貰えるだけで喜びます!(`・ω・´)b" required="required" />
      </div>
    </div>
    <div class="form-group">
      <div class="col-md-offset-2 col-md-10">
        <button class="btn btn-primary" type="submit">送信</button>
      </div>
    </div>
  </form>
  <hr />
  <h3 class="text-center">
    Qiitaの投稿記事
  </h3>
  <p class="text-center">
    このサンプルは下記リンクの投稿用の物です。
  </p>
  <div class="text-center">
    <a href="http://qiita.com/snowsunny/items/56a85c63598dcfb1b06e">【短いコードで色々出来る】Google Apps Scriptでスプレッドシートと連携した無料Ajaxフォームの作り方※サンプル付き【自動返信メールもあるよ】</a>
  </div>
</div>
              
            
!

CSS

              
                form.form-horizontal
  .label.label-danger
    border-radius: 4px
    border-bottom-left-radius: 0px
    border-bottom-right-radius: 0px
  input[required]
    border-top-left-radius: 0px
    
              
            
!

JS

              
                $ ->
  required_tag = '<span class="label label-danger">必須</span>'
  requires = $('form [required]').each (i, elm)->
    $(elm).before required_tag

  $('form').validate
    debug: true
    submitHandler: (e)->
      form = $ e
      btn_submit = form.find('button[type=submit]')
      $.ajax
        url: form.attr 'action'
        dataType: 'jsonp'
        data: form.serialize()

        beforeSend: ->
          btn_submit.attr 'disabled', true
        complete: ->
          btn_submit.attr 'disabled', false

        success: (response)->
          console.log response
          # 成功したらサンクスページとかに飛ばす処理の例↓
          # window.location.href = 'https://codepen.io/snowsunny'
        error: (response)->
          console.log response

              
            
!
999px

Console