I made sure the caching on that page was off (it was). Then I made sure that the snippet calls with eFormOnBeforeFormParse and eFormOnBeforeMailSent functions were not cached. This was something I should have checked too. Thanks. Still did not fix the problem. Very strange!
Ooo good call on the single quoted string. I tried it with the same result. But I added an echo statement again to see it the if condition was being entered and it is, but the checkbox attribute STILL isn’t there. Wacky!
Here is where the code stands:
<?php
function regDocsMenu(&$fields, &$templates)
{
global $modx; // Access to DocumentParser
//set up some array variable
$lines = array();
$doclist = array();
//check the URL for any query string vars for requested docs
if (isset($_GET['docid'])) {
$requested = $_GET['docid'];
} else {
$requested = 0;
}
//get the PDF document list from MODx text document
$dittoOutput = $modx->runSnippet(
"Ditto",
array(
"parents" => "49",
"tpl" => "dittoDocListing",
"showInMenuOnly" => "0",
"display" => "all",
"depth" => "3",
"hideFolders" => "1",
"showPublishedOnly" => "1",
"hidePrivate" => "1"
)
);
//separate the lines of documents
$lines = explode("|~", $dittoOutput);
//loop through and grab file name and title
foreach ($lines as $line) {
if (!empty($line) || $line != "") {
$tempArr = explode("||", $line);
array_push($doclist, $tempArr);
}
}
//start the list of boxes
$output = "<ul>";
//add each document title and filename as label checkboxes
foreach ($doclist as $item) {
$output .= "\t<li><label for=\"document".$item[0]."\"><input type=\"checkbox\" id=\"document".$item[0]."\" name=\"requested_documents[]\" value=\"".trim($item[2])."\"";
### This conditional statement is getting ignored
//check to see if it is a selected document
if( $item[0] == $requested ) {
echo '**entered**';
$output .= ' checked="checked"';
}
$output .= "/>".$item[0]."-".$item[1]."</label></li>\n";
//$output .= '<div>'.$item[0].'</div>';
//$output .='<div>'.$requested.'</div>';
}
$output .= "</ul>";
## This allows setting some checkboxes onload. But doesn't hold the states
//$fields['docsmenu'] = $output;
## This doesn't allow checkboxes set onload, but does hold checkbox states
$templates['tpl'] = str_replace( '[+docsmenu+]', $output, $templates['tpl']);
return true;
}
?>