Hi,
I have problems to send an email with form field values which are modified via $hook->setvalues.
The snippet proofs for empty form fields and set their values to a defined default.
the test shows, that it should function because the values seams to be set,
but the result email shows no values instead.
The fields which are set within the form are listet properly.
property set: hooks = ’recaptcha,spam,email,fillEmptyWithDefault,redirect’
<?php
/* Checks if an input field is empty and fills it with a default value.
* Usage, e.g. in FormIt: ...&hooks=`fillEmptyWithDefault, ...`
*/
$success = false;
$processFields = array();
//get properties
$defaultValue = $modx->getOption('default',$scriptProperties,'0');
$fieldPattern = $modx->getOption('fieldpattern',$scriptProperties,'');
//get input fields
$allFormFields = $hook->getValues();
//set input fields to default if empty (and matchs the pre-selection)
foreach($allFormFields as $formFieldKey => $formFieldVal) {
if (empty($formFieldVal) and (empty($fieldPattern) or preg_match($fieldPattern, $formFieldKey)))
$processFields[$formFieldKey] = $defaultValue;
}
$hook->setValues($processFields);
$success = true;
////TEST:
//$allSetFormFields = $hook->getValues();
//$success = false;
//$errorMsg = print_r($allFormFields,true).'::'.print_r($processFields,true).'::'.print_r($allSetFormFields,true);
//$hook->addError('fields',$errorMsg);
return $success;
Can someone help please?
[MODx Revo 2.0.7, FormIt 1.5.3]
Thx & regards,
svebor