Support the ongoing development of Laravel.io →
posted 8 years ago
Forms
Last updated 2 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!

Eventy

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.

© 2024 Laravel.io - All rights reserved.