I am relatively new to jQuery and I am having a problem with dynamically adding form elements using jQuery then iterating through those form elements with PHP to add to a database.
Basically what I have is a table and upon clicking a div, a new table row is added which contains the form elements. The code looks like this:
$('.addRow1').click(function() {
<?php $count++; ?>
$('.mainTable > tbody:last').one().append('<tr><td>Chronic Pain Referral</td><td>Chronic referral</td><td><input type="hidden" name="count" value="<?php echo $count; ?>"><textarea name="notes"></textarea></td></tr>');
});
As you can see, I attempted to add a counter using PHP so each time a row was added it would add 1 to $count and then I could simply do a foreach() statement to iterate through the form data for each row.
However this didn't work. I get a server error if I try to use foreach() with the counter, and if I simply add a lot of table rows and click submit, when I print the counter value, it always ends up as 1 no matter how many rows I add.
<?php $count++; ?>is running only one time on the server.HTTPprotocol: how jQuery performsHTTPrequests and how PHP handles them [and generatesHTTPresponses accordingly].