I haven’t tried jqrelCopy yet but you’re problem with your code only saving the last row might be because your order row field elements are not in an array format, so newly added rows would just be overwriting previous row elements with the same name. You could try updating your order form element names to be multidimensional arrays with a unique key per row then loop through them when you start inserting data to your database. Your form elements could look something like this:
$customer = new Customer;
$orders = array();
if (isset($_POST['Customer']))
{
$valid = true;
$customer->attributes = $_POST['Customer'];
$valid = $customer->validate() && $valid;
if (!empty($_POST['Order']))
{
// Validate each order row and store in the $orders array
foreach ($_POST['Order'] as $key => $orderPost)
{
$order = new Order;
$order->attributes = $orderPost;
$valid = $order->validate() && $valid;
$orders[$key] = $order;
}
if ($valid)
{
if ($customer->save(false))
{
// Loop through all orders and save each one
foreach ($orders as $order)
{
$order->save(false);
}
}
}
}
}
There might be an error or 2 in there, just something I wrote done real quick but hopefully you get the idea.