0

I created a form to my User database change his password, as it follows :

<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %>
  <%= devise_error_messages! %>
  <%= f.hidden_field :reset_password_token %>


 <div class="container">
 <form action="/action_page.php">
 <%= f.label :password, "Nova senha" %><br />
    <% if @minimum_password_length %>
  <em>(Mínimo de <%= @minimum_password_length %> caracteres)</em><br />
    <% end %>
    <%= f.password_field :password, autofocus: true, autocomplete: "off" %>
 </div>

 <div class="container">
     <%= f.label :password_confirmation, "Confirmar nova senha" %><br />
    <%= f.password_field :password_confirmation, autocomplete: "off" %>
 </form>
</div>

<div class="actions">
    <%= f.submit "Alterar minha senha" %>
  </div>
 <% end %>

The problem about it is that my f.submit "Alterar minha senha" is not working, it doesn't receive the action of my click. How can I fix it ?

  • Maybe if you posted the rendered HTML we could tell you? If ANYTHING in a form is called submit, you cannot submit the form using script – mplungjan Jul 13 '20 at 14:42

2 Answers2

2

The problem is likely that nested formed are not allowed in HTML. You have defined two separate forms, one inside the other. The first is generated by your call to form_for. The second is defined by your <form> tag. Thus, what is probably happening is that your submit button is also submitting the fields on the inner form.

By looking at your code, it appears that you don't even need the inner form—you use the FormBuilder f object from form_for to generate your inner form. However, either way, you should consider re-arranging your forms so that they are not nested.

Also, on a side note, your HTML is invalid. Your closing </form> tag comes before the closing </div> tag for .container.

Jacob Lockard
  • 808
  • 6
  • 17
0

You now have 2 forms, one created by form_for() and then you difine another form in your html the button is not in the html form so it wont submit those fields. Either remove the tag from your html or move the button within the form tag

Nico Shultz
  • 1,743
  • 1
  • 7
  • 20