1
votes

I am using Devise gem which provides a 'Forgot your password' form and 'Resend confirmation' form. Both consist of an input field for e-mail and a submit button. I would like to combine these two forms into one, so that there's only one e-mail field and two submit buttons. Depending on whether 'Reset password' or 'Resend confirmation' button is pressed the form will be submitted to the associated action.

Update: Basically, I would like to have these two forms:

<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %>
  <%= devise_error_messages! %>
  <div><%= f.label :email %><br />
  <%= f.email_field :email, :autofocus => true %></div>
  <div><%= f.submit "Send me reset password instructions" %></div>
<% end %>

<%= form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f| %>
  <%= devise_error_messages! %>
  <div><%= f.label :email %><br />
  <%= f.email_field :email, :autofocus => true %></div>
  <div><%= f.submit "Resend confirmation instructions" %></div>
<% end %>

to share the f.label :email input, but post to action for which the button was pressed. For instance, the :email value will be submitted to confirmation_path when I press "Resend confirmation instructions" button, and when I press f.submit "Send me reset password instructions" the :email value will be posted to password_path(resource_name).

1
Could you provide some code? That would be helpful for anyone trying to answer this. - Drew Gaynor

1 Answers

0
votes

The easiest solution would be to have an input field with a javascript onkeydown listener that will update two hidden input fields for 'resend confirmation' form and 'password reset' form with an e-mail value entered into visible input field. The email value will then be submitted into the form action for which the submit button was pressed.