logo

Get all field data after form submit in Livewire

Here is a first way, you could actually do this right now:

<form wire:submit.prevent="submit(Object.fromEntries(new FormData($event.target)))">
    <input type="text" name="foo">
    <input type="text" name="bar">

    <button>Submit</button>
</form>

Then, in your component, here’s the submit method:

public function submit($formData)
{
    dd($formData);
}

After typing in “baz” and “bob” into the inputs and submitting, this will output:

I'm Murad Saifi, an experienced freelance website designer and developer with over 5 years of industry expertise. Specializing in PHP and the Laravel Framework, I've successfully delivered diverse projects, including e-commerce websites, CRM, CMS platforms, matrimony website and web portals. With skills in crafting secure back-end panels, integrating APIs, and payment gateways, I ensure seamless functionality.

During my free time, I enjoy writing blogs on various topics like web technology, internet trends, android, website security, AI, and ChatGPT. With a deep passion for the industry and a commitment to staying up-to-date, I share valuable insights and expertise on my blog. Join me as we explore the ever-evolving world of web design, development, and the exciting realm of technology.

Leave a Reply

Your email address will not be published. Required fields are marked *