With new CSRF protection we have a fair number places where action buttons have become full forms, or links need to use JS to submit a form. We have generally agreed that the form should be in the page, and the js can add the necessary values for POSTing I think we should go a step further and have a class that can be used to submit a form via a link with data elements, i.e. <a class="btn btn-default btn-xs submit-form-link" href="#" data-adjustment_id="[% adjustment.adjustment_id | html %]" data-invoiceid="[% invoiceid | html %]" data-action="invoice.pl" data-method="post" data-op="cud-del_adj" data-confirmation="confirm_delete_adjustment">
Created attachment 162835 [details] [review] Bug 36246: Add JS function/include for submitting forms from link data This patch adds a new js include file form-submit.js which will read data elements from a link and use those to submit a form This patch fixes forms on acqui/invoice.pl as an example To test: 1 - Add some invoices for a vendor 2 - Got to Acquisitions->Invoices 3 - Actions -> Close - confirm it works 4 - Got to 'Closed invoices' - reopen 5 - Go to Details on the invoice 6 - Add an adjustment 7 - Delete the adjustment 8 - Confirm it works
Created attachment 163098 [details] [review] Bug 36246: Add JS function/include for submitting forms from link data This patch adds a new js include file form-submit.js which will read data elements from a link and use those to submit a form This patch fixes forms on acqui/invoice.pl as an example To test: 1 - Add some invoices for a vendor 2 - Got to Acquisitions->Invoices 3 - Actions -> Close - confirm it works 4 - Got to 'Closed invoices' - reopen 5 - Go to Details on the invoice 6 - Add an adjustment 7 - Delete the adjustment 8 - Confirm it works Signed-off-by: David Nind <david@davidnind.com>
If you cancel then click again you won't get the confirmation and the form will be submitted.
Created attachment 163517 [details] [review] Bug 36246: Add the confirmation text directly to the attribute To avoid the eval and have all the values together. For discussion.
Created attachment 164830 [details] [review] Bug 36246: Add JS function/include for submitting forms from link data This patch adds a new js include file form-submit.js which will read data elements from a link and use those to submit a form This patch fixes forms on acqui/invoice.pl as an example To test: 1 - Add some invoices for a vendor 2 - Got to Acquisitions->Invoices 3 - Actions -> Close - confirm it works 4 - Got to 'Closed invoices' - reopen 5 - Go to Details on the invoice 6 - Add an adjustment 7 - Delete the adjustment 8 - Confirm it works Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Created attachment 164831 [details] [review] Bug 36246: Add the confirmation text directly to the attribute To avoid the eval and have all the values together. For discussion. Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Created attachment 164832 [details] [review] Bug 36246: (follow-up) Fix confirm Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
(In reply to Jonathan Druart from comment #3) > If you cancel then click again you won't get the confirmation and the form > will be submitted. Fixed, we shouldn't delete the confirmation message (to avoid form population) unless the confirm happens (In reply to Jonathan Druart from comment #4) > Created attachment 163517 [details] [review] [review] > Bug 36246: Add the confirmation text directly to the attribute > > To avoid the eval and have all the values together. > > For discussion. I love this! I didn't know how to do this, but I think it is the proper way
Created attachment 165967 [details] [review] Bug 36246: Add JS function/include for submitting forms from link data This patch adds a new js include file form-submit.js which will read data elements from a link and use those to submit a form This patch fixes forms on acqui/invoice.pl as an example To test: 1 - Add some invoices for a vendor 2 - Got to Acquisitions->Invoices 3 - Actions -> Close - confirm it works 4 - Got to 'Closed invoices' - reopen 5 - Go to Details on the invoice 6 - Add an adjustment 7 - Delete the adjustment 8 - Confirm it works Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Created attachment 165968 [details] [review] Bug 36246: Add the confirmation text directly to the attribute To avoid the eval and have all the values together. For discussion. Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Created attachment 165969 [details] [review] Bug 36246: (follow-up) Fix confirm Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Created attachment 165970 [details] [review] Bug 36246: (QA follow-up) New JS should start tidy Add the `/* keep tidy */` flag so the new file stays tidy Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Created attachment 165971 [details] [review] Bug 36246: (QA follow-up) Add missing filter Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Nice re-usable component introduced here... QA scripts happy and new file is tidy now.. I added a couple of very minor QA follow-ups. Passing QA Question: Where can/should we document these sorts of little helpers.. we're really bad at getting them widely adopted/advertised for use.
Pushed for 24.05! Well done everyone, thank you!
Not backported to 23.11.x Maybe needs a coding guideline.
(In reply to Fridolin Somers from comment #16) > Not backported to 23.11.x > > Maybe needs a coding guideline. Added it to the next agenda: https://wiki.koha-community.org/wiki/Development_IRC_meeting_29_May_2024
This doesn't seem to change anything in the manual. Please reopen with more detail if needed.
https://wiki.koha-community.org/wiki/Coding_Guidelines#JS16:_JavaScript_form_submission_via_links