Submit Button - Which is best? Which is right?

Can somebody explain what the difference is between these two different ways of using a Submit button and why you would use one over the other?

<button type="submit" class="btn btn-primary">Save</button>

<button type="button" class="btn btn-primary" dmx-on:click="[form_name].submit()">Save</button>

For submitting forms you should use the submit button.
https://www.w3schools.com/tags/att_button_form.asp
Why use JavaScript events for some functionality which is natively offered by the submit button?

The submit event could be useful when you want to submit the form using some dynamic event attached to some other element/server action, outside of the form.

2 Likes

OK that’s great.

I was wondering if there was a Wappler reason for using the second option. There is, but only if you want to use some other dynamic action at the same time, otherwise use the first option. Cheers.

1 Like

yes, submit button is the best way HOWEVER just occasionally i may wish to place a button outside a form, for example in a modal footer, and in such a case I would use the click event to trigger the submission as the submission wouldn’t trigger as the button is outside the form.

3 Likes

Ahh! That’s why my form is no longer submitting. Thanks for your input Brian.

Your question is actually something i was planning on commenting about today so excellent timing

1 Like