0

几天前,我正在构建的应用程序的注册表单运行良好。即使没有填写表单字段,“创建我的帐户”按钮也会起作用,并且会立即显示错误消息。现在,当我尝试提交表单时,只有在填写完所有字段后,表单才会提交或显示错误消息。如果我尝试在不填写所有字段的情况下提交表单,则不会发生任何事情。注册按钮无法正常工作。

我能想到的唯一重大改变是将我使用的条带计划转换为免费试用计划,而不是应用程序购买者预付费用的计划。我不知道是什么导致了这个问题,所以我不知道我应该发布什么代码。您可以提供的任何帮助将不胜感激。

我在 rails 中的注册表单如下(减去我用于 Stripe 的一些 javascript):

<div class="row">
<div class="span6 offset4">
    <%= form_for(@user) do |f| %>

        <%= render 'shared/error_messages' %>

        <%= f.label :name %>
        <%= f.text_field :name %>

        <%= f.label :email %>
        <%= f.text_field :email %>

        <%= f.label :password %>
        <%= f.password_field :password %>

        <%= f.label :password_confirmation, "Password confirmation" %>
        <%= f.password_field :password_confirmation %>

        <%= f.label :morning_meds, "Do you take medications in the morning?" %>
        <%= f.select :morning_meds, [['Yes'], ['No']] %>

        <%= f.label :lunch_meds, "Do you take medications at lunch?" %>
        <%= f.select :lunch_meds, [['Yes'], ['No']] %>

        <%= f.label :night_meds, "Do you take medications in the evening?" %>
        <%= f.select :night_meds, [['Yes'], ['No']] %>

        <%= f.label :time_zone, "Choose your time zone" %>
        <%= f.select :time_zone, [['Eastern'], ['Central'], ['Mountain'], ['Pacific']] %>

        <%= f.label :phone_number, "Your cell phone number" %>
        <%= f.text_field :phone_number %>

        <div class="form-row">
                    <label>Card Number</label>
                    <input type="text" size="20" autocomplete="off" class="card-number" />
                </div>
                <div class="form-row">
                    <label>CVC</label>
                    <input type="text" size="4" autocomplete="off" class="card-cvc" />
                </div>
                <div class="form-row">
                    <label>Expiration Date</label>
                    <%= select_month nil, {add_month_numbers: true}, {name: nil, class: 'card-expiry-month' } %>
                    <span> / </span>
                    <%= select_year nil, {start_year: Date.today.year, end_year: Date.today.year+15}, {name: nil, class: 'card-expiry-year' } %>
                </div>

    <%= f.submit "Create my account", class: "btn btn-large btn-primary" %>
    <% end %>
</div>
</div>





   <div class="row"> 
    <div class="span6 offset4"> 
        <form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="authenticity_token" type="hidden" value="QqrFVykfeY1+9jImvp8VjTzrQxq8VlBF+vC6V85klw0=" /></div> 



            <label for="user_name">Name</label> 
            <input id="user_name" name="user[name]" size="30" type="text" /> 

            <label for="user_email">Email</label> 
            <input id="user_email" name="user[email]" size="30" type="text" /> 

            <label for="user_password">Password</label> 
            <input id="user_password" name="user[password]" size="30" type="password" /> 

            <label for="user_password_confirmation">Password confirmation</label> 
            <input id="user_password_confirmation" name="user[password_confirmation]" size="30" type="password" /> 

            <label for="user_morning_meds">Do you take medications in the morning?</label> 
            <select id="user_morning_meds" name="user[morning_meds]"><option value="Yes">Yes</option> 
    <option value="No">No</option></select> 

            <label for="user_lunch_meds">Do you take medications at lunch?</label> 
            <select id="user_lunch_meds" name="user[lunch_meds]"><option value="Yes">Yes</option> 
<option value="No">No</option></select> 

            <label for="user_night_meds">Do you take medications in the evening?</label> 
            <select id="user_night_meds" name="user[night_meds]"><option value="Yes">Yes</option> 
<option value="No">No</option></select> 

            <label for="user_time_zone">Choose your time zone</label> 
            <select id="user_time_zone" name="user[time_zone]"><option value="Eastern">Eastern</option> 
<option value="Central">Central</option> 
<option value="Mountain">Mountain</option> 
<option value="Pacific">Pacific</option></select> 

            <label for="user_phone_number">Your cell phone number</label> 
            <input id="user_phone_number" name="user[phone_number]" size="30" type="text" /> 

            <div class="form-row"> 
                        <label>Card Number</label> 
                        <input type="text" size="20" autocomplete="off" class="card-number" /> 
                    </div> 
                    <div class="form-row"> 
                        <label>CVC</label> 
                        <input type="text" size="4" autocomplete="off" class="card-cvc" /> 
                    </div> 
                    <div class="form-row"> 
                        <label>Expiration Date</label> 
                        <select class="card-expiry-month" id="date_month"> 
<option value="1">1 - January</option> 
<option value="2">2 - February</option> 
<option value="3">3 - March</option> 
<option value="4">4 - April</option> 
<option value="5">5 - May</option> 
<option value="6">6 - June</option> 
<option value="7">7 - July</option> 
<option value="8">8 - August</option> 
<option value="9">9 - September</option> 
<option value="10">10 - October</option> 
<option value="11">11 - November</option> 
<option value="12">12 - December</option> 
</select> 

                        <span> / </span> 
                        <select class="card-expiry-year" id="date_year"> 
<option value="2012">2012</option> 
<option value="2013">2013</option> 
<option value="2014">2014</option> 
<option value="2015">2015</option> 
<option value="2016">2016</option> 
<option value="2017">2017</option> 
<option value="2018">2018</option> 
<option value="2019">2019</option> 
<option value="2020">2020</option> 
<option value="2021">2021</option> 
<option value="2022">2022</option> 
<option value="2023">2023</option> 
<option value="2024">2024</option> 
<option value="2025">2025</option> 
<option value="2026">2026</option> 
<option value="2027">2027</option> 
</select> 

                    </div> 

        <input class="btn btn-large btn-primary" name="commit" type="submit" value="Create my account" /> 
</form> 
4

1 回答 1

0

It'd be helpful to see the HTML source your view generates, but you likely have 1+ fields with the HTML5 required attribute that you are leaving blank.

By default, newer browsers like Chrome will not allow the form to submit until all fields flagged with the required attribute have a value. To stop this you can add the novalidate attribute to the <form ... tag.

<%= form_for(@user, { :novalidate => true }) do |f| %>
于 2012-07-28T01:41:35.970 回答