Weston,
Super. Amazing script. It works great. For the life of me I don't
think I could come up with this code. Thank you so much.
I modified the script a little bit (see code below) since it wasn't
behaving the way I envisioned it. Everytime I submitted a post, it was
adding 5 new rows and it would hang if I exceeded the number of rows
set to maximum of 7. I ended up setting the repeat-start="1". I also
added code to ignore if the post is blank since it was adding a new
row everytime I posted. I wish I could set 5 rows at the outset and
add 1 row after each submit, but this is great.
Thanks so much for your help. It's much appreciated.
Ulysses
<form id="claim" method="post" enctype="multipart/form-data"
action="<? echo $_SERVER['PHP_SELF']; ?>">
<table>
<?php
$repetitionIndexes = array();
foreach($_POST as $key => $value){
if(preg_match("{^amount_(\d+)}", $key, $matches))
$repetitionIndexes[] = (int)$matches[1];
}
?>
<?php foreach($repetitionIndexes as $i): ?>
<?php if ($_POST['amount_' . $i]=="") { } else {?>
<tr repeat="<?php echo $i ?>" repeat-template="row">
<td><input type="text" name="amount_<?php echo $i ?>" value="<?
php
echo $_POST['amount_' . $i]; ?>"></td>
<td><button type="remove">Delete</button></td>
</tr>
<?php } ?>
<?php endforeach; ?>
<tr repeat="template" id="row" repeat-start="5" repeat-min="1" repeat-
max="7">
<td><input type="text" name="amount_[row]" value="<?php echo
$_POST['amount_[row]']; ?>"></td>
<td><button type="remove">Delete</button></td>
</tr>
<button type="add" template="row">Add Row</button>
</table>
</form>