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.
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 []).
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community