Send parameters with submit

I need two submit buttons in a form – one controller action will process them in slightly different ways. I cannot figure out how to send a parameter which distinguishes button A from button B. I have tried doing this:

<%= submit "Save & Exit", button_pushed: "AAAA" %>
<%= submit "Save ", button_pushed: "BBBB" %>

However, I see none of A, B, button_pushed in conn or the parameters. What am I missing here?

2 Likes

Try:

<%= submit "Save & Exit", name: "button_pushed", value: "A" %>
<%= submit "Save", name: "button_pushed", value: "B" %>

Then you should get a button_pushed parameter with a value of A or B.

(This is not specific to Phoenix, but the way HTML <button> works.)

8 Likes

Thank you – all working beautifully now

2 Likes