We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 2935
    • 15 Posts
    Xpix,
    Good suggestion. I tried that before too, but I went ahead and did your suggestion and
    Here is the crazy part, with the URL of www.mydomain.com/registration?docid=85
    And puting the the code your suggested, here is the output:
    <ul>
    <li><label for="document86" ><input type="checkbox" id="document86" name="requested_documents[]"  value="assets/files/downloads/InternetRetailer.CVN.pdf"  />86-CARD VERIFICATION NUMBERS SERVE OFFLINE WORLD, BUT ARE THEY A REMEDY FOR INTERNET CARD FRAUD?</label></li>
    <div>86</div><div>85</div>
    <li><label for="document85" ><input type="checkbox" id="document85" name="requested_documents[]"  value="assets/files/downloads/ChipCardFraud_WP_FINAL.pdf"  />85-PAYMENT CARD FRAUD IN A CHIP CARD WORLD</label></li>
    <div>85</div><div>85</div>	
    <li><label for="document84" ><input type="checkbox" id="document84" name="requested_documents[]"  value="assets/files/downloads/JECM_The_Fraud_Management_Lifecycle.pdf"  />84-THE FRAUD MANAGEMENT LIFECYCLE® THEORY</label></li>
    <div>84</div><div>85</div>
    </ul>
    


    Notice in the third li tag the numbers match up. So why the input is not checked is a mystery. There is something happening during the parsing of the placeholder that I can’t understand

      • 5340
      • 1,624 Posts
      Is the caching turned off?
        • 5340
        • 1,624 Posts
        try $output .= ’ checked="checked"’;

        Are you sure the IF is not entered?
          • 2935
          • 15 Posts
          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;
          }
          ?>							
          
            • 5340
            • 1,624 Posts
            Is something striping the checked attribute?

            You might try the following:
            Instead of outputting ’checked="checked"’ try ’class="checkedBox"’ and use your favorite JavaScript framework or similar to check it on document ready.



              • 2935
              • 15 Posts
              xpix,
              Yes, that is what I was thinking. Which is why I posted here again. Seems like if eForm is striping out that attribute it doesn’t make sense. If it did that then how would one set a pre-checked/selected input in there form (even one that wasn’t dynamically created).

              Another good call on the class attribute. I will try that. I am already using jQuery and might use that method to do this.

              Thanks for looking this over with me. Guess maybe I am not going nuts.
                • 30223
                • 1,010 Posts
                Your problem has to do with a misunderstanding of how eForm deals with default values, not surprising as it’s not as intuitive as it could be.

                For checkboxes, radio buttons and select boxes default values are not retained from the form template when the form is parsed. To set these you can however set appropriate values in the fields array. If you change the code slightly as shown below it should work.

                //<?php
                // skipped rest of code
                   ### This conditional statement is getting ignored
                   //check to see if it is a selected document
                   if( $item[0] == $requested ) {
                      //$output .= ' checked="checked"';
                      $fields['requested_documents'][count($fields['requested_documents'])]=trim($item[2]);
                   }
                //skipped more code
                


                EDIT: Oops,.. you might want to add in a test to see if the form is posted otherwise the ’defaults’ will show even when the form is posted.

                //<?php
                 if( count($post)==0 || $_POST['formid'] !=$modx->event->params['formid']) 
                      $fields['requested_documents'][count($fields['requested_documents'])]=trim($item[2]);
                

                  • 2935
                  • 15 Posts
                  Yaaayyyy!!! grin Mark this one solved.

                  TobyL,
                  I didn’t mean to say I thought there was something up with the eForm code. What I was trying to say is that I knew there was something I wasn’t understanding, because it didn’t seam likely that it was a programmed behavior. Sorry, if it didn’t come out right in my earlier post. I am not an experienced enough programmer (yet) to look through the eForm code and decipher what I should do. Hopefully others will benefit from my lack of understanding here.

                  Thanks again sir for your support on this forum. That is what makes for a great open source project!