I have been working on a system for tracking vacation days, and I'm currently trying to make it so that within an edit page I can use checkboxes to select table rows (the checkboxes values = the mysql table row id's) and then delete them.
I have it working so that I can select a single row and have it be removed using this snippit. Which you guys helped me with before.
<?php
$path = MODX_CORE_PATH . 'components/track/';
$result = $modx->addPackage('track',$path . 'model/','pto_');
$id = $_POST["1"];
// Get the object we want to delete
$obj = $modx->getObject('Track',$id);
// Check if we actually retrieved an object to prevent fatal errors
$success = true;
if ($obj instanceof Track) {
// if it's the right object, remove it. Will return true or false
$success = $obj->remove();
}
return $success;
I've been trying to pass the checkbox values into an array, and then do a foreach loop but I keep getting an parsing error.
I've tried it two ways, and both give me errors.
#1 is
<?php
$path = MODX_CORE_PATH . 'components/track/';
$result = $modx->addPackage('track',$path . 'model/','pto_');
foreach($_POST["1"] as $deleterow => $id) {
$deleterow = $modx->getObject('Track',$id);
$success = true;
if ($deleterow instanceof Track) {
// if it's the right object, remove it. Will return true or false
$success = $obj->remove();
}
}
return $success;
and #2 is:
<?php
$path = MODX_CORE_PATH . 'components/track/';
$result = $modx->addPackage('track',$path . 'model/','pto_');
$id = $_POST["1"];
// I assume that the rowcheckbox post is a SINGLE ID and not an array.. if so, you'll need to wrap this in a for each or something.
// Get the object we want to delete
$objs = $modx->getObject('Track',array("1",$id));
// Check if we actually retrieved an object to prevent fatal errors
$success = true;
foreach(objs as obj) {
if ($obj instanceof Track) {
// if it's the right object, remove it. Will return true or false
$success = $obj->remove();
}
}
return $success;
Any suggestions?