YouTubevideo· Jul 2, 2024· 2:37
So while recording a video, I learned some new things about HTML forms that were later confirmed by some comments from that video. I thought that when you had a form in HTML, and again, this is just strict HTML standards, I thought when you had a form in HTML, you had to have a type equals submit on a button in that form. But that's not actually true. I can omit the type equals submit and any button in that form becomes a submit button.
So, regardless of how many buttons you have that are in this form tag, here's my primary button, I don't have to have typeu equals submit for that button to work. So, if I say, hey, fantastic day, learned about forms, and I click save, it just works. Now, there's something else that I didn't know as well.
If you have this button, let's say we don't want that submit button in our form. We still want the enter down press on our keyboard to actually submit the form. That's why we're using a form with a wire submit function, a method. Now I want to take this button and place it somewhere else. So instead I want to push this in the dashboard view and we can just place this like right here. Now here's the, here's the interesting part.
Now, in our HTML form, we just have to add an ID that is something that references that particular form. This can be anything, but if I was to go into the button and now add this form attribute with the same ID or the same identifier as this form ID right here, now this button automatically
becomes the submit button for that particular form. This is just HTML, this isn't Laravel or Livewire specific. If I was to say, okay, learn something else new. Buttons don't have to be in the form. And bam, look at that. It just works. And it still runs the same method that we attached within Livewire, the same wire submit
method because it's linking to that particular form to submit that form. So buttons don't have to be in the form, but any button in the form is also automatically a submit button. You don't have to have the type submit. So I learned something new.