如何在Rails中转换此联系表单

时间:2015-09-12 14:12:45

标签: ruby-on-rails ruby forms

我有一个联系表单,我想在rails中将其转换。我在rails中创建了相同的表单,但我想添加其特殊的类,如data-error-empty,data-ok-message和data-error-invalid。

以下是我要在rails中转换的表单

<form  id="contact-form" class="bl_form text-center" action="contact.php" method="post" novalidate>
                    <span class="field-wrap scrollimation fade-right">
                        <label class="control-label" for="contact-name">Name</label>
                        <input id="contact-name" name="contactName" type="text" class="label_better requiredField" data-new-placeholder="Name" placeholder="Name" data-error-empty="*Enter your name">
                    </span>
                    <span class="field-wrap scrollimation fade-in">
                        <label class="control-label" for="contact-mail">Email</label>
                        <input id="contact-mail" name="email" type="email" class="label_better requiredField" data-new-placeholder="Email Address" placeholder="Email Address" data-error-empty="*Enter your email" data-error-invalid="x Invalid email address">
                    </span>
                    <span class="field-wrap scrollimation fade-left">
                        <label class="control-label" for="contact-message">Message</label>
                        <textarea id="contact-message" name="comments" rows="1" class="label_better requiredField" data-new-placeholder="Message" placeholder="Message" data-error-empty="*Enter your message"></textarea>
                    </span>

                    <p class="text-center"><button  name="submit" type="submit" class="btn btn-meflat icon-left" data-error-message="Error!" data-sending-message="Sending..." data-ok-message="Message Sent"><i class="fa fa-paper-plane"></i>Send Message</button></p>
                    <input type="hidden" name="submitted" id="submitted" value="true" />

                </form>

这是我在rails中创建的表单。

  <%= form_for @contact do |f| %>
        <div class="form-group">
          <%= f.label :name %>
          <%= f.text_field :name, class: 'form-control' %>
        </div>
        <div class="form-group">
          <%= f.label :email %>
          <%= f.email_field :email, class: 'form-control' %>
        </div>
        <div class="form-group">
          <%= f.label :message %>
          <%= f.text_area :message, class: 'form-control' %>
        </div>
        <%= f.submit 'Submit', class: 'btn btn-default' %>
      <% end %>

另外如何在主页上添加表单,rails中的表单url是contacts / new。谢谢。

0 个答案:

没有答案