Search code examples
ruby-on-railsbalanced-payments

Converting balanced payments form into Rails


I want to convert this balanced payment form into rails-haml. I tried but my submit button doesn't do anything. Probably because I don't know how to pull of a submit outside of a form_for.

This is the form they gave as an example. Click here to view the whole thing in Jsfiddle.

<form action="#" method="POST" id="credit-card-form">
    <fieldset>
        <legend>Credit Card Details</legend>
        <label>Card Number
            <input type="text"
                   autocomplete="off"
                   placeholder="Card Number"
                   class="cc-number" value="4111111111111111">
        </label>
        <label>Expiration
            <input type="text"
                   autocomplete="off"
                   placeholder="Expiration Month"
                   class="cc-em" value="01">
            <span>/</span>
            <input type="text"
                   autocomplete="off"
                   placeholder="Expiration Year"
                   class="cc-ey" value="2020">
        </label>
        <label>Security Code (CSC)
            <input type="text"
                   autocomplete="off"
                   placeholder="CSC"
                   class="cc-csc" value="123">
        </label>
        <button type="submit" class="btn">
            Tokenize
        </button>
    </fieldset>
</form>

This is what I tried

#credit-card-form
  = label_tag :card_number, "Credit Card Number"
  = text_field_tag :card_number, nil, name: nil, :value => "4111111111111111", class: "cc-number"
  %br
  = label_tag :card_code, "Security Code on Card (CVV)"
  = text_field_tag :card_code, nil, name: nil, :value => "123", class: "cc-csc"
  %br
  = label_tag :card_month, "Card Expiration"
  = select_month nil, {add_month_numbers: true}, {name: nil, id: "cc-em"}
  = select_year Date.new(2020), {start_year: Date.today.year, end_year: Date.today.year+15}, {name: nil, id: "cc-ey"}
  %br
  = submit_tag "Subscribe"

Solution

  • do this

    %form#credit-card-form{:action => "#", :method => "POST"}
      = label_tag :card_number, "Credit Card Number"
      = text_field_tag :card_number, nil, name: nil, :value => "4111111111111111", class: "cc-number"
      %p
      = label_tag :card_code, "Security Code on Card (CVV)"
      = text_field_tag :card_code, nil, name: nil, :value => "123", class: "cc-csc"
      %p
      = label_tag :card_month, "Card Expiration"
      = select_month nil, {add_month_numbers: true}, {name: nil, class: "cc-em"}
      = select_year Date.new(2020), {start_year: Date.today.year, end_year: Date.today.year+15}, {name: nil, class: "cc-ey"}
      %p
      / = submit_tag "Subscribe"
      %button.btn{:type => "submit"}
        tokenize