Submit form from the outside of form using htmx

Viewed 1085

How to submit a form using submit button or input type submit outside of the form? In HTML It can be done easily using form ID but I didn't find the way to submit the form outside of the form in HTMX?

Can anybody help in this regard?

1 Answers

A couple of ways:

  1. Dispatch a submit event to the form using javascript when the button is clicked.

  2. Add the hx-post attribute on the external button and also add hx-include="#your-form-id". This will include all the inputs within the form in the request.

Related