How to submit jquery duplicate/clone field values to form with PHP. It's very basic level code, I had implemented this using relCopy.js jquery plugin to duplicating the existing field. I hope it's useful for you. Thanks!

Download Script
Live DemoJavascript Code
Here input text name hobby[] is array.
<script type="text/javascript" src="http://ajax.googleapis.com/
ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="reCopy.js"></script>
<script type="text/javascript">
$(function(){
var removeLink = ' <a class="remove" href="#" onclick="$(this).parent().slideUp(function(){ $(this).remove() }); return false">remove</a>';
$('a.add').relCopy({ append: removeLink});
});
</script>
ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="reCopy.js"></script>
<script type="text/javascript">
$(function(){
var removeLink = ' <a class="remove" href="#" onclick="$(this).parent().slideUp(function(){ $(this).remove() }); return false">remove</a>';
$('a.add').relCopy({ append: removeLink});
});
</script>
//HTML code
<form method="post" action="clonesubmit.php">
<p class="clone"> <input type="text" name="hobby[]" class='input'/></p>
<p><a href="#" class="add" rel=".clone">Add More</a></p>
<input type="submit" value=" Submit " />
</form>More information :relCopy jQuery Plugin
clonesubmit.php
Contains simple PHP Code that extracting array hobby[] values.
<?php
if($_POST['hobby']){
$array=$_POST['hobby'];
foreach($array as $hobby)
{
if(strlen($hobby)>0)
{
$sql=mysql_query("insert into hobbies(hobby)values('$hobby')");
}
}
}
?>







very useful tnkx
Hello, Fantastic script....Chears..
Excellent!!!
That's very useful script. But how to add limit for duplicated fields. For example, I want to allow users create no more than 5 fields.
@Sandis
Use this code
$('a.copy').relCopy({limit: 5, append: removeLink});
Very usefull. Thanks
Hi, mi name is vicman, and this library is very usefull.
But I found several things to improve.
1-function callback when the re-copy operation has finished.
2-The radio button should not clear the value when it is duplicated.
Thanks.
I need to have each "clone" or "copy" input field have a different name. Like "input_1", and "input_2". Is this possible? Thanks.
Great stuff!
Although if I have two individual forms on the same page, and click "Add More" on the second form, input's get added to the first form :(
How do I separate them?
I have a question, i use rows with 7 inputs on each row, it is possible to use this function to add a hole row and then post it into the Mysql?
wau , your script it's amaizing
mm this is how to insert data clone into database,how about if i want update data?? can you help me ^_^ btw tengs before
how about ,post this value from ajax?? can you explaine please ^_^
HOW CAN I PREVENT DUPLICATION OF INPUTS IN PHP.EXAMPLE IS NO DUPLICATION OF NAME??REPLY ASAP...TNX
Excellent!!! thanx sir
Thanks a lot, it is useful
i will use this tehnique in polling engine,
Is there a way to add the new fields to validation?
hi Srinivas,
i found this snippet very useful, thanks.
but i found if i implement with jquery date picker, it won't duplicate.
helo bro...
first thanks for the code..
but, how can we count 'how many field' in our form??
thanks..
reply as soon as posible
it's not working on tables:(
Hi, great script - thanks for sharing. Question - if I want to use animate({ opacity: "hide" }, "slow"); - as you do in several of your other scripts instead of the slideup - how should that look?
how if i want to use date picker? ive tried and it does not working.. can u help plz me. tx :)
@aMaddun
Use jquery live method
How can add numbering in each new item?
1. input
2. input
3. input
Harika tam istedigim bir konu teşekkürler :)
I have been trying to find this for days. If i'm using a dynamic form like this one, how can I use PHP to get all the values submitted via e-mail? I can do it with a regular form but I have no idea of how to get the duplicates...
I’m trying to add multiple cloned input boxes with another input all in the same table and same record; does anyone have any ideas?
Can I make it so the cloned input does something like cloning the fields as needed?
Hi, great script - thanks for sharing.
Question - i want multiple fields to clone...
plz suggest...
tried alot... didn't find nething... :(
peace and quality, great script, i customize it to my code and works great. thanks a lot!!!
simple n nice script, but how to work with image input? (cz seems like I failed to do it, will try to debug it further..) tq
Is it possible to add a delete confirm alert using jqury inlineconfirmation? I tried a couple of ways and see the confirm yes/no message, but it does the delete action anyway and deletes both the line and the confirmation text.
how can you put validation on cloned fields.
Great code. Like Max Allan I use multiple values in each row. I have them duplicating but having trouble with the insertion into the MySQL database. Do you have an example with multiple values in each row? Thanks
Thanks! Really simple and useful! Works like a charm for me, even on tables! Thank you so much my friend! Keep posting
@MCHS, just name your field like this: field_name[] . Pls note on the bracket []. That will put all entries on an array, so PHP can process them later on.
On PHP, capture all arrays using JOIN function. So the entries will be saved to DB like this: JOHN,ANDREW,AHMAD,RONNIE,DONALD
Hope this help :)