We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28975
    • 4 Posts
    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
      • 28975
      • 4 Posts
      Ok sorry - our fault! rolleyes
      Hook sequence was not correct, it should be ’recaptcha,spam,fillEmptyWithDefault,email,redirect’.
      I think I had validators in mind instead of hooks when I checked it further - shame on me :’(

      Regards,
      svebor

      P.S. feel free to use the code...
      its simple but could be usefull e.g. ordering something from a dynamic list and filter the email output in a tpl like this
      [[getResources@propertyset_xxx? &parents=`id_yyy` &tpl=`[[+quantity_[[+id]]:ne=`0`:then=`<p>[[+quantity_[[+id]]]] x [[+pagetitle]]</p>`:else=``]]`]]

      where the fieldpattern property of the hook snippet can be set to /^quantity_/
      (I think this are the relevant infos grin)