|
Start by rendering all of the required fields, with the correct names and values:
<?php foreach ($rowIDs as $id) { ?>
<input type="hidden" name="rowIDs[]" value="<?php echo $id; ?>">
<input type="hidden" name="<?php echo 'sourcename' . $id ?>" value="<?php echo $_POST['sourcename' . $id]; ?>">
<input type="hidden" name="<?php echo 'sourceaddress' . $id ?>" value="<?php echo $_POST['sourceaddress' . $id]; ?>">
<input type="hidden" name="<?php echo 'income' . $id ?>" value="<?php echo $_POST['income' . $id]; ?>">
<?php }?>
<?php foreach ($row2IDs as $id) { ?>
<input type="hidden" name="row2IDs[]" value="<?php echo $id; ?>">
<input type="hidden" name="<?php echo 'spousename' . $id ?>" value="<?php echo $_POST['spousename' . $id]; ?>">
<input type="hidden" name="<?php echo 'spouseAddress' . $id ?>" value="<?php echo $_POST['spouseAddress' . $id]; ?>">
<input type="hidden" name="<?php echo 'spouseIncome' . $id ?>" value="<?php echo $_POST['spouseIncome' . $id]; ?>">
<?php } ?>
In final.php , you read them using the same code:
$rowIDs = $_POST['rowIDs'];
foreach ($rowIDs as $id) {
$sourcename = $_POST['sourcename' . $id];
$sourceaddress = $_POST['sourceaddress' . $id];
$income = $_POST['income' . $id];
...
}
$row2IDs = $_POST['row2IDs'];
foreach ($row2IDs as $id) {
$spousename = $_POST['spousename' . $id];
$spouseAddress = $_POST['spouseAddress' . $id];
$spouseIncome = $_POST['spouseIncome' . $id];
...
}
The only slight issue is that you won't be able to have the source and spouse on the same row in your database table, because they're independent lists. You'll have to put them on different rows:
$sql = 'INSERT INTO `myDB`.`wp_myTable` ( `employeeID`'
. ', `sourcename`, `sourceaddress`, `income` )'
. ' VALUES ( ? , ? , ? , ? )';
if( $sth = mysqli_prepare($conn,$sql) ) {
mysqli_stmt_bind_param($sth, 'ssss',
$last_id,
$sourcename,
$sourceaddress,
$income);
$rowIDs = $_POST['rowIDs'];
foreach ($rowIDs as $id) {
$sourcename = $_POST['sourcename' . $id];
$sourceaddress = $_POST['sourceaddress' . $id];
$income = $_POST['income' . $id];
mysqli_stmt_execute($sth);
}
mysqli_stmt_close($sth);
}
$sql = 'INSERT INTO `myDB`.`wp_myTable` ( `employeeID`'
. ', `spousename`,`spouseAddress`,`spouseincome` )'
. ' VALUES ( ? , ? , ? , ? )';
if( $sth = mysqli_prepare($conn,$sql) ) {
mysqli_stmt_bind_param($sth, 'ssss',
$last_id,
$spousename,
$spouseAddress,
$spouseIncome);
$row2IDs = $_POST['row2IDs'];
foreach ($row2IDs as $id) {
$spousename = $_POST['spousename' . $id];
$spouseAddress = $_POST['spouseAddress' . $id];
$spouseIncome = $_POST['spouseIncome' . $id];
mysqli_stmt_execute($sth);
}
mysqli_stmt_close($sth);
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
YEA!!!!!!!!!!!!!!!!!!!!!!
wow!!!
I don't know if I should stand up and dance.
WOW!
My manager gave till 9AM tomorrow to get it working. Needless to say, I didn't sleep well last night.
Sorry I am just responding now because I just got to work.
I responded earlier from work.
Richard D, I don't know if you remember me saying this a couple of years ago.
There is guy called Bill Wilkinson, one of the best in this business.
Like you, he would say, not familiar with this but he ends up solving it.
Like him, anytime you are involved in my thread, I feel a weight lifted off me because like him, you always see that the issue is resolved.
THANK YOU.
Ok, let me calm down and ask a few questions.
As you may know, there are many more fields than this.
From your comment, they will all end up inserting into different rows.
The good news is that they belong to same employeeID.
So, how do I tie them up together when I attempt to display the records?
I probably need UNION ALL and GROUP BY?
Boy, I feel so relieved.
As always, thanks for coming to my rescue - again!
You are such a load of talent. Is there something you don't know about technology?
I have spent over a week on this with really great experts and they still could not get it to work for me.
|
|
|
|
|
Personally, I'd be inclined to split them into multiple tables - "employee details", "source details", and "spouse details". You'd have a one-to-many relationship from the employee details table to the source details table, and another from the employee details table to the spouse details table.
To display the full details, you'd then have three queries: one to get the employee details; one to get the list of source details; and one to get the list of spouse details.
SELECT `employeename`, `ttitle`, `email` FROM `myDB`.`wp_employeeDetails` WHERE `employeeID` = ?
SELECT `sourcename`, `sourceaddress`, `income` FROM `myDB`.`wp_sourceDetails` WHERE `employeeID` = ?
SELECT `spousename`, `spouseAddress`, `spouseincome` FROM `myDB`.`wp_spouseDetails` WHERE `employeeID` = ?
You could do that with your current design, but you'd need some way to identify whether a record was the employee details, the source details, or the spouse details. It could get quite messy.
SELECT `employeename`, `ttitle`, `email` FROM `myDB`.`wp_myTable` WHERE `employeeID` = ? AND `employeename` Is Not Null
SELECT `sourcename`, `sourceaddress`, `income` FROM `myDB`.`wp_myTable` WHERE `employeeID` = ? AND `sourcename` Is Not Null
SELECT `spousename`, `spouseAddress`, `spouseincome` FROM `myDB`.`wp_myTable` WHERE `employeeID` = ? AND `spousename` Is Not Null
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Ok I see.
So, let me say for instance that I have these three tables (they will be up to 7).
CEATE TABLE employees (
employeeid INT NOT NULL,
employeename varchar(25),
ttitle varchar(25),
email varchar(25),
PRIMARY KEY (employeeid)
);
create table wp_spousedetails
(
spouseid INT NOT NULL,
name varchar(30) not null,
foreign key (employeeid) references menus(employeeid),
primary key (spouseid)
);
create table wp_sourcedetails
(
sourceid INT NOT NULL,
name varchar(30) not null,
foreign key (employeeid) references menus(employeeid),
primary key (sourceid)
);
Please don't worry if there is any syntax error with these. That's not the point of posting these ddl statements. I can fix those.
My question is to reference them all, all I need is employeeid, no?
Select e.employeename, e.ttitle, e.email, so.sourcename,so.sourceincome, sp.spousename,sp.spouseincome.... from employees e on so.employeeid = e.employeeid, sp.employeeid = e.employeeid.
That's really all I need right?
I am trying to calm down from excitement. This has been agonizing.
Thank you, thank you sir
|
|
|
|
|
Essentially, but if you join all of the tables together, you're going to get the details repeated across multiple rows.
For example, if employee 1 has 3 sources and 2 spouses, you'll get six rows:
Employee Source Spouse
-----------------------------
1 A X
1 A Y
1 B X
1 B Y
1 C X
1 C Y
That may or may not work, depending on your requirements.
With three separate queries, filtered by the employee ID, you'd get one record for the employee, three records for the sources, and two records for the spouses.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
LAST question (I can't believe that I have arrived at this), the query that I need between the two queries you posted is the bottom portion of the queries?
|
|
|
|
|
From this message[^], the second set of queries should work with your current, single-table design. You'd use the first set if you split the data into three tables.
Obviously, you'll need to fix up the table and column names to match your database, and add any missing columns to the queries.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you very.
My anxiety level has dropped to almost zero since your solution.
You saved me again.
Your reward, I promise will come one day.
May not be from me but it will come.
|
|
|
|
|
Hi Richard,
Sorry for calling you out but I did because I needed an urgent help.
This is the code you helped me out with (Thanks again).
//markup
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Forms</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.6/handlebars.min.js"></script>
<style type="text/css">
.bs-example{
margin-left: 250px;
margin-top: 30px;
}
</style>
</head>
<body>
<form class="form-inline" action="<?php echo get_option('siteurl'); ?>/forms/preview.php" id="contactForm" role="form" method="post">
<div class="form-group">
<label for="employeename">Employee Name</label><br>
<input type="text" name="employeename" id="employeename" style="width:375px;" placeholder="your name..." class="form-control" value="" class="required requiredField" />
</div>
<div class="form-group">
<label for="ttitle">Title</label><br>
<input type="text" name="ttitle" id="ttitle" style="width:375px;" placeholder="Your title..." class="form-control" value="" class="required requiredField" />
</div><br><br>
<script id="row-template" type="text/x-handlebars-template">
<div>
<!--reseed attribute IDs in case of gap resulting from deletions -->
<input type="hidden" name="rowIDs" value="{{rowNumber}}" />
<div class="form-group">
<label for="sourcename1{{rowNumber}}">Name</label><br>
<input type="text" name="sourcename1{{rowNumber}}" id="sourcename1{{rowNumber}}" value="" class="required requiredField" />
<?php if($nameError != '') { ?>
<?=$nameError;?>
<?php } ?>
</div>
<div class="form-group">
<label for="sourceaddress1{{rowNumber}}">Address</label><br>
<input type="text" name="sourceaddress1{{rowNumber}}" id="sourceaddress1{{rowNumber}}" style="width:250px;" class="form-control" value="" class="required requiredField" />
<?php if($nameError != '') { ?>
<?=$nameError;?>
<?php } ?>
</div>
<div class="form-group">
<label for="income1{{rowNumber}}">Income</label><br>
<input type="text" style="width:250px;" class="form-control" name="income1{{rowNumber}}" id="income1{{rowNumber}}" value="" class="required requiredField" />
<?php if($nameError != '') { ?>
<?=$nameError;?>
<?php } ?>
</div>
<input id="Button{{rowNumber}}" type="button" rel="remove-row" value="Remove" />
</div>
</script>
<div id="addrow" data-row-count="1" data-template-id="row-template">
<div>
<!--
<input type="hidden" name="rowIDs" value="1" />
<div class="form-group">
<label for="sourcename1">Name</label><br>
<input type="text" name="sourcename1[]" id="sourcename1" value="" class="required requiredField" />
<?php if($nameError != '') { ?>
<?=$nameError;?>
<?php } ?>
</div>
<div class="form-group">
<label for="sourceaddress1">Address</label><br>
<input type="text" name="sourceaddress1[]" id="sourceaddress1" style="width:250px;" class="form-control" value="" class="required requiredField" />
<?php if($nameError != '') { ?>
<?=$nameError;?>
<?php } ?>
</div>
<div class="form-group">
<label for="income1">Income</label><br>
<input type="text" name="income1[]" id="income1" style="width:250px;" class="form-control" value="" class="required requiredField" />
<?php if($nameError != '') { ?>
<?=$nameError;?>
<?php } ?>
<input type="button" value="Add More" rel="add-row" data-target="addrow" />
</div>
</div>
</div><br><br>
<script id="row-template-2" type="text/x-handlebars-template">
<div>
<!--reseed attribute IDs in case of gap resulting from deletions -->
<input type="hidden" name="row2IDs" value="{{rowNumber}}" />
<div class="form-group">
<input type="text" style="width:250px;" class="form-control" name="spousename{{rowNumber}}" id="spousename{{rowNumber}}" value="" class="required requiredField" />
<?php if($nameError != '') { ?>
<?=$nameError;?>
<?php } ?>
</div>
<div class="form-group">
<input type="text" style="width:250px;" class="form-control" name="spouseAddress{{rowNumber}}" id="spouseAddress{{rowNumber}}" value="" class="required requiredField" />
<?php if($nameError != '') { ?>
<?=$nameError;?>
<?php } ?>
</div>
<div class="form-group">
<input type="text" style="width:250px;" class="form-control" name="spouseIncome{{rowNumber}}" id="spouseIncome{{rowNumber}}" value="" class="required requiredField" />
<?php if($nameError != '') { ?>
<?=$nameError;?>
<?php } ?>
</div>
<input id="Button{{rowNumber}}" type="button" rel="remove-row" value="Remove" />
</div>
</script>
<div id="addrow2" data-row-count="1" data-template-id="row-template-2">
<div>
<!--
<input type="hidden" name="row2IDs" value="1" />
<div class="form-group">
<label for="spousename">Name</label><br>
<input type="text" style="width:250px;" class="form-control" name="spousename[]" id="spousename" value="" class="required requiredField" />
<?php if($nameError != '') { ?>
<?=$nameError;?>
<?php } ?>
</div>
<div class="form-group">
<label for="spouseAddress">Address</label><br>
<input type="text" style="width:250px;" class="form-control" name="spouseAddress[]" id="spouseAddress" value="" class="required requiredField" />
<?php if($nameError != '') { ?>
<?=$nameError;?>
<?php } ?>
</div>
<div class="form-group">
<label for="spouseIncome">Income</label><br>
<input type="text" style="width:250px;" class="form-control" name="spouseIncome[]" id="spouseIncome" value="" class="required requiredField" />
<?php if($nameError != '') { ?>
<?=$nameError;?>
<?php } ?>
<input type="button" value="Add More" rel="add-row" data-target="addrow2" />
</div>
</div>
</div> <br><br>
<div class="form-group">
<label for="email">Email</label><br>
<input type="text" style="width:750px;" class="form-control" name="email" id="email" value="" class="required requiredField email" />
<?php if($emailError != '') { ?>
<?=$emailError;?>
<?php } ?>
</div>
<button type="submit" class="btn btn-primary">Submit</button><br>
<input type="hidden" name="submitted" id="submitted" value="true" />
</form>
<script type='text/javascript'>
$(function(){
var templates = {
"row-template": Handlebars.compile($("#row-template").html()),
"row-template-2": Handlebars.compile($("#row-template-2").html())
};
$("form").on("click", "input[rel='add-row']", function(){
var containerId = $(this).data("target");
var container = $("#" + containerId);
var templateId = container.data("templateId");
var template = templates[templateId];
var rowCount = container.data("rowCount");
rowCount++;
var context = { rowNumber: rowCount };
var html = template(context);
container.append(html);
container.data("rowCount", rowCount);
});
$("form").on("click", "input[rel='remove-row']", function(){
var row = this.parentNode;
var container = row.parentNode;
container.removeChild(row);
});
});
</script>
</body>
</html>
//Server side:
".print_r($_POST, 1)."";
if(isset($_POST['employeename']))
$employeename = $_POST['employeename'];
if(isset($_POST['ttitle']))
$ttitle = $_POST['ttitle'];
$rowIDs = $_POST['rowIDs'];
echo $employeename .' ';
echo $ttitle .' ';
for ($id = 0; $id < $rowIDs; $id++){
$sourcename1 = $_POST['sourcename1'][$id];
$sourceaddress1 = $_POST['sourceaddress1'][$id];
$income1 = $_POST['income1'][$id];
$spousename = $_POST['spousename'][$id];
$spouseAddress = $_POST['spouseAddress'][$id];
$spouseIncome = $_POST['spouseIncome'][$id];
echo 'Name: '. $sourcename1 .' ';
echo 'Address: '. $sourceaddress1.' ';
echo 'Income: '. $income1.' ';
echo 'Name: '. $spousename .' ';
echo 'Address: '. $spouseAddress.' ';
echo 'Income: '. $spouseIncome.' ';
}
?>
<input type='text' name='employeename' value="<?php echo="" $employeename?="">">
<input type='text' name='ttitle' value="<?php echo="" $ttitle;="" ?="">">
<input type='text' name='sourcename1[]' value="<?php echo="" $sourcename1;="" ?="">">
<input type='text' name='sourceaddress1[]' value="<?php echo="" $sourceaddress1;="" ?="">">
<input type='text' name='income1[]' value="<?php echo="" $income1;="" ?="">">
There are two problems here and I think they are all related.
1, When I run the code, it is displaying only one row of data.
When I click to add another row and then fill enter data into that row, it doesn't display it.
2, Second issue is the error I am getting which says,
Notice: Undefined offset: 1 in C:\xampp\htdocs\disclosures\forms\preview.php on line 13
Notice: Undefined offset: 1 in C:\xampp\htdocs\disclosures\forms\preview.php on line 14
Notice: Undefined offset: 1 in C:\xampp\htdocs\disclosures\forms\preview.php on line 15
Notice: Undefined offset: 1 in C:\xampp\htdocs\disclosures\forms\preview.php on line 16
Notice: Undefined offset: 1 in C:\xampp\htdocs\disclosures\forms\preview.php on line 17
Notice: Undefined offset: 1 in C:\xampp\htdocs\disclosures\forms\preview.php on line 18
Any ideas what I am doing wrong?
Man, I am supposed to demo this app this afternoon.
Many thanks in advance
modified 23-Feb-17 8:59am.
|
|
|
|
|
samflex wrote: $sourcename1 = $_POST['sourcename1'][$id];
That should be:
$sourcename1 = $_POST['sourcename1' . $id];
Same for the other fields.
samflex wrote: When I run the code, it is displaying only one row of data.
Because you're only rendering a single row in the HTML. The additional rows are added via script when you click the button.
samflex wrote: When I click to add another row and then fill enter data into that row, it doesn't display it.
What do you mean?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
phew!
Thanks so much Richard for coming to my rescue again.
The reason I changed to this:
$sourcename1 = $_POST['sourcename1'][$id];
was because the one you suggested I use which I just used again just now was giving the error below:
tice: Undefined index: sourcename10 in C:\xampp\htdocs\disclosures\forms\preview.php on line 13
My concern was that I didn't screw something up in the markup. I tried to follow the solution you provided.
What I meant by your question is that when I Add another row, it is not being captured on my php server code.
|
|
|
|
|
samflex wrote: Undefined index: sourcename10 in C:\xampp\htdocs\disclosures\forms\preview.php on line 13
Because you're using:
for ($id = 0; $id < $rowIDs; $id++)
so $id is the index, not the value.
Use the "foreach" version[^], as I suggested, and $id will be the value:
for ($rowIDs as $id)
If you want to stick to the standard for loop, you'll need to use:
for ($index = 0; $index < $rowIDs; $index++){
$id = $rowIDs[$index];
$sourcename1 = $_POST['sourcename1' . $id];
...
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Believe me sir,
I see your solutions as money in the bank.
However, when I tried that original FOR loop you gave me, I got this:
rning: Invalid argument supplied for foreach() in C:\xampp\htdocs\disclosures\forms\preview.php on line 12
Now, I just tried your latest solution and this is what I am getting.
Notice: Undefined index: sourcename11 in C:\xampp\htdocs\disclosures\forms\preview.php on line 14
Notice: Undefined index: sourceaddress11 in C:\xampp\htdocs\disclosures\forms\preview.php on line 15
Notice: Undefined index: income11 in C:\xampp\htdocs\disclosures\forms\preview.php on line 16
Notice: Undefined index: spousename1 in C:\xampp\htdocs\disclosures\forms\preview.php on line 17
Notice: Undefined index: spouseAddress1 in C:\xampp\htdocs\disclosures\forms\preview.php on line 18
Notice: Undefined index: spouseIncome1 in C:\xampp\htdocs\disclosures\forms\preview.php on line 19
Name:
Address:
Income:
-----------
Name:
Address:
Income:
I am just wandering if the problem is in the markup.
Kind of frustrating.
I really appreciate your help.
modified 21-Feb-17 15:19pm.
|
|
|
|
|
Try changing the name of the hidden inputs to rowIDs[] , both in the Handlebars template and the static HTML row.
<input type="hidden" name="rowIDs[]" value="{{rowNumber}}" />
...
<input type="hidden" name="rowIDs[]" value="1" />
$rowIDs = $_POST['rowIDs'];
for ($rowIDs as $id) {
...
}
It looks like PHP needs the [] on the end of the form field name in order to treat the posted values as an array.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Right.
I have added them and now this:
Notice: Undefined index: sourcename11 in C:\xampp\htdocs\disclosures\forms\preview.php on line 13
Notice: Undefined index: sourceaddress11 in C:\xampp\htdocs\disclosures\forms\preview.php on line 14
Notice: Undefined index: income11 in C:\xampp\htdocs\disclosures\forms\preview.php on line 15
Notice: Undefined index: spousename1 in C:\xampp\htdocs\disclosures\forms\preview.php on line 16
Notice: Undefined index: spouseAddress1 in C:\xampp\htdocs\disclosures\forms\preview.php on line 17
Notice: Undefined index: spouseIncome1 in C:\xampp\htdocs\disclosures\forms\preview.php on line 18
Same errors. Unreal!
Thanks for your patience sir.
|
|
|
|
|
OK, remove the "1" from the field names in the template, and from the PHP script:
<input type="text" name="sourcename{{rowNumber}}" id="sourcename{{rowNumber}}" value="" class="required requiredField" />
<!--
$sourcename1 = $_POST['sourcename' . $id];
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Nope,
Infact changing ROWIDS to rowIDs[] seems to have multiplied how many of those errors are rendered.
It's like million records (errors) displayed when infact, only entered records into two rows.
Who would have thought this would be this challenging.
Maybe I can all over from the markup to make that it is correct before looking at the php server side script?
Sorry for all the inconvenience sir.
|
|
|
|
|
Looks like you've already added [] to some fields that don't need it.
<script id="row-template" type="text/x-handlebars-template">
<div>
<!--reseed attribute IDs in case of gap resulting from deletions -->
<input type="hidden" name="rowIDs[]" value="{{rowNumber}}" />
<div class="form-group">
<label for="sourcename{{rowNumber}}">Name</label><br>
<input type="text" name="sourcename{{rowNumber}}" id="sourcename{{rowNumber}}" value="" class="required requiredField" />
</div>
<div class="form-group">
<label for="sourceaddress{{rowNumber}}">Address</label><br>
<input type="text" name="sourceaddress{{rowNumber}}" id="sourceaddress{{rowNumber}}" style="width:250px;" class="form-control" value="" class="required requiredField" />
</div>
<div class="form-group">
<label for="income{{rowNumber}}">Income</label><br>
<input type="text" style="width:250px;" class="form-control" name="income{{rowNumber}}" id="income{{rowNumber}}" value="" class="required requiredField" />
</div>
<input id="Button{{rowNumber}}" type="button" rel="remove-row" value="Remove" />
</div>
</script>
<div id="addrow" data-row-count="1" data-template-id="row-template">
<div>
<input type="hidden" name="rowIDs[]" value="1" />
<div class="form-group">
<label for="sourcename1">Name</label><br>
<input type="text" name="sourcename1" id="sourcename1" value="" class="required requiredField" />
<?php if($nameError != '') { ?>
<span class="error"><?=$nameError;?></span>
<?php } ?>
</div>
<div class="form-group">
<label for="sourceaddress1">Address</label><br>
<input type="text" name="sourceaddress1" id="sourceaddress1" style="width:250px;" class="form-control" value="" class="required requiredField" />
<?php if($addressError != '') { ?>
<span class="error"><?=$addressError;?></span>
<?php } ?>
</div>
<div class="form-group">
<label for="income1">Income</label><br>
<input type="text" name="income1" id="income1" style="width:250px;" class="form-control" value="" class="required requiredField" />
<?php if($incomeError != '') { ?>
<span class="error"><?=$incomeError;?></span>
<?php } ?>
</div>
<input type="button" value="Add More" rel="add-row" data-target="addrow" />
</div>
</div>
$rowIDs = $_POST['rowIDs'];
for ($rowIDs as $id) {
$sourcename = $_POST['sourcename' . $id];
$sourceaddress = $_POST['sourceaddress' . $id];
$income1 = $_POST['income' . $id];
echo 'Name: '. $sourcename1 . '<br />';
echo 'Address: '. $sourceaddress1 . '<br />';
echo 'Income: '. $income1 . '<br />';
}
NB: You'll need a separate loop to read the spouse name, address and income.
If it still doesn't work, check what values are being submitted to your PHP script.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I just tried your latest code. I entered records into the first row, dynamically added another row and populated that as well.
Below is the debug output as well as the errors.
This AngularJS dynamic code is so gorgeous and works great in terms of the markup but this has been an unbelievable nightmare for me.
Richard, sir, I am wondering if you can give me a hint on how to make the original code I posted look as pretty as this one you did.
What I mean is that the page once loaded looks nice and is nicely laid out but when you click to Add another row, the new row looks different.
Since I can't get this to work and I begged my manager for another, perhaps that might be easier to implement?
DEBUG POST DATA: Array
(
[employeename] =>
[ttitle] =>
[rowIDs] => 1
[sourcename1] => John Doe
[sourceaddress1] => 123 Doe street
[income1] => $36,000.00
[sourcename12] => Jane Doe
[sourceaddress12] => 23 Jane Way
[income12] => $67,000.00
[spousename] => Array
(
[0] =>
)
[spouseAddress] => Array
(
[0] =>
)
[spouseIncome] => Array
(
[0] =>
)
[email] =>
[submitted] => true
)
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\disclosures\forms\preview.php on line 14
Notice: Undefined variable: sourcename1 in C:\xampp\htdocs\disclosures\forms\preview.php on line 28
"> Notice: Undefined variable: sourceaddress1 in C:\xampp\htdocs\disclosures\forms\preview.php on line 29
"> Notice: Undefined variable: income1 in C:\xampp\htdocs\disclosures\forms\preview.php on line 30
"> Notice: Undefined variable: spousename in C:\xampp\htdocs\disclosures\forms\preview.php on line 31
"> Notice: Undefined variable: spouseAddress in C:\xampp\htdocs\disclosures\forms\preview.php on line 32
"> Notice: Undefined variable: spouseIncome in C:\xampp\htdocs\disclosures\forms\preview.php on line 33
|
|
|
|
|
samflex wrote: [rowIDs] => 1
...
sourcename12
Why have you ignored my suggestion to remove the extra "1" from the field names in the template, and to add the [] suffix to the name of the rowIDs fields?
If you'd followed my suggestions, the submitted data would look like:
[rowIDs] => Array
(
[0] => 1
[1] => 2
)
[sourcename1] => John Doe
[sourceaddress1] => 123 Doe street
[income1] => $36,000.00
[sourcename2] => Jane Doe
[sourceaddress2] => 23 Jane Way
[income2] => $67,000.00
NB: rowIDs is an array, and the fields from the row have sequential names - sourcename1 , sourcename2 , etc.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Why have you ignored my suggestion to remove the extra "1" from the field names in the template, and to add the [] suffix to the name of the rowIDs fields? Confused |
I didn't sir.
I thought the code you showed there was the correct code I should use.
I copied the code and that's the code I tested with and that's actually the code I am testing with now.
The only change I made now was to remove the "1" in the line below:
<input type="hidden" name="rowIDs[]" value="" /> and used it as you see it now.
The good news is that for the first time, I did not get the "ivalid'''
Here is what it looks like now and the current error. I also noticed that one fieldname says, sourcename and down the line, it says sourcename1. Same with sourceaddress and income.
Are they by design?
BUG POST DATA: Array
(
[employeename] => James Brown
[ttitle] => IT Manager
[rowIDs] => Array
(
[0] =>
)
[sourcename1] => Mary Tyler Moore
[sourceaddress1] => 123 Tyler Street
[income1] => $2000,000.00
[email] =>
[submitted] => true
)
James Brown
IT Manager
Notice: Undefined index: sourcename in C:\xampp\htdocs\disclosures\forms\preview.php on line 17
Notice: Undefined index: sourceaddress in C:\xampp\htdocs\disclosures\forms\preview.php on line 18
Notice: Undefined index: income in C:\xampp\htdocs\disclosures\forms\preview.php on line 19
Notice: Undefined variable: sourcename1 in C:\xampp\htdocs\disclosures\forms\preview.php on line 21
Name:
Notice: Undefined variable: sourceaddress1 in C:\xampp\htdocs\disclosures\forms\preview.php on line 22
Address:
Income:
|
|
|
|
|
samflex wrote: The only change I made now was to remove the "1" in the line below:
And by doing that, you've broken the code I posted in yet another way!
Put the value="1" back in on that line. You're looking for a POST data of:
[rowIDs] => Array
(
[0] => 1
)
Then the loop will find the first ID is "1", and on the first iteration, will look for "sourcename1".
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
YEA!!!!
IT IS WORKING!!!!!!
Oh gosh, I can't thank you enough for saving me yet again.
Your patience is incredible and will be emulated.
Thank you so much Richard.
You have tremendous and thank you for sharing.
You will be greatly rewarded for your generosity.
I got pulled into offsite work yesterday and I am just getting back to you
Many THANKS sir.
|
|
|
|
|
Glad to hear it!
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi
I have one application that receives the images from bing, I am using the api of bing, but I want save the images for I use them without internet. How I can do this? Somebody can help me?
|
|
|
|
|