2

我想将这种平衡支付形式转换为 rails-haml。我试过了,但我的提交按钮没有做任何事情。可能是因为我不知道如何在 form_for 之外提交提交。

这是他们作为示例给出的表格。单击此处查看 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>

这是我尝试过的

#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"
4

2 回答 2

2

做这个

%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
于 2013-07-20T05:39:46.247 回答
1

使用 html2haml:

%form#credit-card-form{:action => "#", :method => "POST"}
  %fieldset
    %legend Credit Card Details
    %label
      Card Number
      %input.cc-number{:autocomplete => "off", :placeholder => "Card Number", :type => "text", :value => "4111111111111111"}/
    %label
      Expiration
      %input.cc-em{:autocomplete => "off", :placeholder => "Expiration Month", :type => "text", :value => "01"}/
      %span /
      %input.cc-ey{:autocomplete => "off", :placeholder => "Expiration Year", :type => "text", :value => "2020"}/
    %label
      Security Code (CSC)
      %input.cc-csc{:autocomplete => "off", :placeholder => "CSC", :type => "text", :value => "123"}/
    %button.btn{:type => "submit"}
      Tokenize
于 2013-07-20T10:32:12.707 回答