Jquery Duplicate Fields Form Submit with PHP.
💻 coding

Jquery Duplicate Fields Form Submit with PHP.

1 min read 112 words
1 min read
ShareWhatsAppPost on X
  • 1The article explains how to submit jQuery duplicate fields in a form using PHP.
  • 2It utilizes the relCopy.js jQuery plugin to clone existing input fields.
  • 3The PHP code processes submitted data by inserting non-empty hobby values into a database.

AI-generated summary · May not capture all nuances

Key Insight
AskGif

"The article explains how to submit jQuery duplicate fields in a form using PHP."

Jquery Duplicate Fields Form Submit with PHP.

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.

<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>
//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>

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')");
}

}
}
?>

Enjoyed this article?

Share it with someone who'd find it useful.

ShareWhatsAppPost on X

AskGif

Published on 5 August 2019 · 1 min read · 112 words

Part of AskGif Blog · coding

You might also like

Jquery Duplicate Fields Form Submit with PHP. | AskGif Blog