We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 53376
    • 32 Posts
    I have forms with different quizes for testing users and I need to send quiz results on E-mail.

    I have custom hook for it, but I don't know how to set custom message text without using external chunk. How to do it?

    I tried to use default ability to send field names and values, but it unable to remove default pairs (key => value):

    <?php
    $allFields = $hook->getValues();
    $qtpair = array();
    $newval = array();
    $newval['User'] = $modx->getPlaceholder('joomlaUser');
    $p_t = $modx->resource->get('pagetitle');
    $l_t = $modx->resource->get('longtitle');
    $newval['Lesson'] = (empty($l_t) ? $p_t : $l_t);
    $newval['Resource ID'] = ''.$modx->resource->get('id');
    foreach ($allFields as $k => $v) {
    	if (strpos($k, 'question') !== false) {
    		$qtpair[(int)preg_replace('/[^0-9]+/', '', $k)] = $v;
    	}
    }
    
    foreach ($allFields as $k => $v) {
    	if (strpos($k, 'answer') !== false) {
    		$aid = (int)preg_replace('/[^0-9]+/', '', $k);
    		if (empty($newval[ $qtpair[$aid] ])) $newval[ $qtpair[$aid] ] = $v;
    		else $newval[ $qtpair[$aid] ] = $newval[ $qtpair[$aid] ].'<br>'.PHP_EOL.$v;
    	}
    }
    
    foreach ($allFields as $k => $v) {
    	$hook->setValue($k, null); // Trying to remove default pairs (key => value)
    }
    
    $hook->setValues($newval); // Instead default, we setting quiz pairs (question => answer) as (key => value)
    return true;
      • 53376
      • 32 Posts
      I found the way only in creating new chunk (with name 'temp_quiz_'.md5($username)) before running email-hook, and removing this chunk in next hook, which executing after email-hook