We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38593
    • 129 Posts
    I am trying to bring a rather complicated booking form into MODX and am having issues with one aspect of the PHP.

    We have a function that looks at the tourcode value and depending on the first two letters chooses which T&C to display. The tourcodes are basically 3 letters and 3 or 4 numerals (tha1302, akh121, bhm134, etc). The PHP function I can't seem to incorporate uses substr to strip out the first two characters.

    The original PHP version used in our old non-CMS website:
    	$trip = substr($tourcode, 0, 2);
    	if ($trip == bh) { include "/...../terms60.inc";  }
    	else { include "/...../terms45.inc"; }


    The proposed MODX version:
    	$trip = substr($tourcode, 0, 2);
    	if ($trip == bh) { $modx->setPlaceholder('tandc', 'tac60'); }
    	else { $modx->setPlaceholder('tandc', 'tac45'); }


    In MODX the 'tandc' value always defaults to the 'tac45' no matter what tourcode I use. In PHP it works as expected. So I am guessing there is some issue with snippets vs php that I haven't accounted for.

    And yes I am sure that the $tourcode value is present as it is used successfully elsewhere in the same snippet.
      Pedalers Bicycle Tours my website forged with MODX
      vandergraaf-M static website generator for MODX
    • That should be
      if ($trip == 'bh') { ... }


      Also, make sure you are calling the snippet non-cacheable. Is the tourcode value coming from a $_REQUEST variable?
        • 38593
        • 129 Posts
        Adding the quotes around bh didn't seem to change the functionality. I have provided all of the applicable code below:
        	$tourcode = $_GET['tourcode'];
        	$tourid = $_GET['tourid'];
        	$go = $_POST['go'];
        	
        	if ((isset($tourcode)) && (empty($go))) {
        		// display first panel without calendar
        		$modx->setPlaceholder('bkform', 'book0');
        		$modx->setPlaceholder('tourcode', $tourcode);
        		// choose tandc
        		$trip = substr($tourcode, 0, 2);
        		if ($trip == 'bh') { $modx->setPlaceholder('tandc', 'tac60'); } 
        	        else { $modx->setPlaceholder('tandc', 'tac45'); }
        		}
        
        	elseif .....(different combos of tourid, tourcode & go)


        The use of both GET & POST is deliberate as feeds to this form come from either links (GET) or from a form (POST). The 'choose tandc' code is only used in this IF statement, not in any of the subsequent ELSEIF statements. The $tourcode value is present as the Placeholder 'tourcode' appears in the final outputed html.

        The call to this snippet in the template is non-cached using the '!' before the snippet name.
          Pedalers Bicycle Tours my website forged with MODX
          vandergraaf-M static website generator for MODX
          • 38593
          • 129 Posts
          Not sure what happened. But all of a sudden it started working, guess something was hung up on my server or ??
            Pedalers Bicycle Tours my website forged with MODX
            vandergraaf-M static website generator for MODX