I have a big form.
This form contains some inputs that can be duplicated by the user.
So they can choose for example how many Claimants have worked on a song and enter some fields for EACH claimant, with a limit of 10 Claimants.
The form will look like this (I will show only 3 now)
echo "<form action=\"\" id=\"submForm\" name=\"submForm\" method=\"get\">";
//1 CLAIMANT
echo "<p><span class=\"labelInput\">".(_t('_cR_name_mandatory'))." </span><input id=\"nameClaimant\" name=\"nameClaimant[]\" value=\"\" type=\"text\" class=\"required commonInput\"></p>";
echo "<p><span class=\"labelInput\">".(_t('_cR_DOB_mandatory'))." </span><input id=\"DOBClaimant\" name=\"DOBClaimant[]\" value=\"\" type=\"text\" class=\"required littleInput\"></p>";
echo "<p><span class=\"labelInput\">".(_t('_cR_company'))." </span><input id=\"companyClaimant\" name=\"companyClaimant[]\" value=\"\" type=\"text\" class=\"commonInput\"></p>";
//2 CLAIMANT
echo "<p><span class=\"labelInput\">".(_t('_cR_name_mandatory'))." </span><input id=\"nameClaimant\" name=\"nameClaimant[]\" value=\"\" type=\"text\" class=\"required commonInput\"></p>";
echo "<p><span class=\"labelInput\">".(_t('_cR_DOB_mandatory'))." </span><input id=\"DOBClaimant\" name=\"DOBClaimant[]\" value=\"\" type=\"text\" class=\"required littleInput\"></p>";
echo "<p><span class=\"labelInput\">".(_t('_cR_company'))." </span><input id=\"companyClaimant\" name=\"companyClaimant[]\" value=\"\" type=\"text\" class=\"commonInput\"></p>";
//3 CLAIMANT
echo "<p><span class=\"labelInput\">".(_t('_cR_name_mandatory'))." </span><input id=\"nameClaimant\" name=\"nameClaimant[]\" value=\"\" type=\"text\" class=\"required commonInput\"></p>";
echo "<p><span class=\"labelInput\">".(_t('_cR_DOB_mandatory'))." </span><input id=\"DOBClaimant\" name=\"DOBClaimant[]\" value=\"\" type=\"text\" class=\"required littleInput\"></p>";
echo "<p><span class=\"labelInput\">".(_t('_cR_company'))." </span><input id=\"companyClaimant\" name=\"companyClaimant[]\" value=\"\" type=\"text\" class=\"commonInput\"></p>";
echo "<input type=\"submit\" class=\"submBttnClass\" id=\"buttSubm\" name=\"buttSubm\" value=\"".(_t('_cR_submit_button'))."\">";
echo "</form>";
When the user submits the form I use a jQuery serialize function (I am on jQuery 1.3.2)
echo "<script type=\"text/javascript\">
$(document).ready(function() {
$('#submForm').validate({
submitHandler: function(form) {
var serialized = $('#submForm').serialize()
$.get('".$site['url']."modules/yobilab/copyright/classes/DO_submission.php', serialized);
//alert($('#submForm').serialize());
window.setTimeout('location.reload()', 8000);
return false;
form.submit();
}
})
The problem is that the file that processes the Insert in the Database uses a foreach(I will show you my entire foreach with all the inputs that are passed with the serialize function:
if(!empty($_GET['nameClaimant'])){
$nameClaimant = $_GET['nameClaimant'];
$DOBClaimant = $_GET['DOBClaimant'];
$companyClaimant = mysql_real_escape_string($_GET['companyClaimant']);
$emailClaimant = $_GET['emailClaimant'];
$mainPhoneClaimant = $_GET['mainPhoneClaimant'];
$alternatePhoneClaimant = $_GET['alternatePhoneClaimant'];
$mobilePhoneClaimant = $_GET['mobilePhoneClaimant'];
$percentageClaimant = mysql_real_escape_string($_GET['percentageClaimant']);
$addressClaimant = mysql_real_escape_string($_GET['addressClaimant']);
$ZIPClaimant = $_GET['ZIPClaimant'];
$countryClaimant = $_GET['countryClaimant'];
foreach ($nameClaimant as $valueClaimant) {
$insClaim = "INSERT INTO cR_Claimants SET memberID ='".$memberID."', ParentSubmission='".$refNumb."', Name ='".mysql_real_escape_string($valueClaimant)."', DOB='".$DOBClaimant."', Company='".$companyClaimant."', Email='".$emailClaimant."', Address='".$addressClaimant."', ZIPcode ='".$ZIPClaimant."', Country='".$countryClaimant."', MainPhone='".$mainPhoneClaimant."', OtherPhone='".$alternatePhoneClaimant."', MobilePhone='".$mobilePhoneClaimant."', OwnershipPercentage='".$percentageClaimant."'";
$resultinsClaim=mysql_query($insClaim) or die("Error insert Claimants: ".mysql_error());
}
}
The foreach inserts in the database wrong stuff. It shows Array instead of the right value.
I would like to insert the info in the database consequentially with my foreach.
So for Claimant1 will insert its relative info
for Claimant2 will insert its relative info and so on.
It is not working. What am I doing wrong?
I know it is a little boring, but please help me! Lets play with it. You are All great Thank you
I have attached what is doing in the database to let you see
You will see that is also creating empty strings in the database.
Why is that taking also empty values?
Please help me.
