Support the ongoing development of Laravel.io →
posted 9 years ago
Forms

I’m very new to Laravel so please forgive me if this is a daft question.

I’m not even sure of the name of what I want so I don’t know what to search for but what I want to do is have a form that allows more than one row of data to be entered at once.

Something like this:

			[First Name]	[Surname]	[DOB]	
			John			Doe		05/05/1986

Add Another-> Add Another->

			[Submit]

Is this even possible? And if so what would something like this be called?

Many thanks.

Last updated 3 years ago.
0

To accomplish that, you'll first need some JavaScript. As an example, have a look at this fiddle.

HTML:

<p>Users</p>
<ul id="users-list">
    <li><input type="text" name="names[]" value="" placeholder="enter name" /></li>
</ul>
<button id="add-more">Add More Users</button>

JS (using jQuery):

$(document).ready(function() {
    $users_list = $('#users-list');
    $add_more = $('#add-more');
    
    $add_more.on('click', function() {
        $users_list.find('li:first').clone().find(':input').val('').end().appendTo($users_list);
    });
});

Don't pay much attention to the actual code (it doesn't even include a form or a submit button, it's just a rough example); mostly focus on the logic so you can adapt it for your needs.

After you submit your form, the "names" input will be an array of strings instead of a single string (as it would be without the []).

0

Thanks for the help that pointed me perfectly in the right direction.

0

Sign in to participate in this thread!

PHPverse

Your banner here too?

0w3n86 0w3n86 Joined 8 Nov 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.