So I thought you could use eform and ditto to solve your problem. That would give you the most control over the look without having to touch the back end.
So I created a document container called gifts with rich text off ( you can call it whatever you like)
Then put these two snippet calls on that page
[!GiftStuff!]
[!eForm? &formid=`gf` &eFormOnBeforeFormParse=`getGifts` &eFormOnBeforeMailSent=`removeGifts` &tpl=`giftForm` &thankyou=`thanks`!]
The GiftStuff snippet holds the getGifts function used by eFormOnBeforeParse and the removeGifts function used by eFormOnBeforeMailSent.
The eform call is going to run the getGifts function before the form is diplayed and that function will run a ditto call to pull the gift pages inside the gifts container. The eFormOnBeforeMailSent runs the removeGifts function which will un publish any documents that the user selects using the checkboxes.
Here is the GiftStuff snippet
// dynamically insert ditto output into eforms
function getGifts(&$fields, &$templates) {
global $modx;
// run ditto from php
// if you ditto call is more complicated just add more $params variable ($params['Ditto Param without the &'])
$params['tpl'] = 'giftRow'; // assign giftRow template to Ditto
$giftList = $modx->runSnippet('Ditto', $params); // run ditto
// create gifts placeholder for eform
$templates['tpl']=str_replace('[+gifts+]', $giftList, $templates['tpl']);
}
// process form submit
function removeGifts(&$fields) {
global $modx;
$table = $modx->getFullTableName('site_content');
foreach($fields as $field=>$value) {
//split the checkbox name on the dash
list($prefix, $title) = split("-",$field);
// if prefix everything left of the dash is gift and the value is not blank then run database update
if($prefix == 'gift' && $value != '') {
$id = $modx->db->escape($value);
if(!$unpub = $modx->db->query("UPDATE $table SET published = 0 WHERE id = $id")) echo '<div class="error">Were Sorry! There was a problem and your selection was not saved</div>'; return false;
}
}
return true;
}
You will also need to create a chunk for your ditto call. I called it giftRow. You will notice that in the getGifts function above there is a line with $params[’tpl’] = ’giftRow’. You will need to change that line to whatever your chunk is called or leave it as is if your chunk is called giftRow. Also remember that you need to create a new $params variable for every ditto parameter you want to run ( eg. $param[’sortBy’] = ’editedon’; ). Also note you are not using backticks here you are using single quotes.
My ditto template is pretty basic you can change yours however you want just make sure the name for check box is
gift-[+id+]. It will not work without it.
I used the pagetitle to put the title of the gift. You could use whatever document fields you like. Basically ditto the way you normally would.
giftRow chunk
<input type="checkbox" name="gift-[+id+]" value="[+id+]" eform="[+pagetitle+]::0">[+pagetitle+]
and lastly the eform tpl
giftForm
[+validationmessage+]
<form action="[~[*id*]~]" method="post" name="giftForm" id="gf">
[+gifts+]
<input type="submit" name="submit" value="Purchase Gift">
</form>
The [+gifts+] placeholder is created by the getGifts function from above
I almost forgot. In the eform snippet call there is a thanks chunk you need to make or you can take it out and use the default thank for eform.
Hope that helps let me know if you are having any problems or questions. I was in a bit of hurry so let me know if there are any mistakes.
Angelo