We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33372
    • 1,611 Posts
    I’ve run into an unexpected issue with my usual pre-populating event function: It doesn’t seem to work for textarea fields. If I replace the field name below with one that refers to a regular input field (e.g., name, email), this code works as expected. But textareas don’t seem to have their values pre-parsed using this method.

    function preFormParse(&$fields){
    
       global $modx;
       $evt=&$modx->event;
       $validFormId=($evt->params['formid']==$_POST['formid']);
       $isPostBack=($validFormId && count($_POST)>0);
       
       if (!$isPostBack) { // Check for NOT postback, since we only want to prepopulate an empty form
          $fields['message']=<<<EOF
    letter text here...
    EOF;
       }
       else { // the form has been posted, so pre-process any data here
          // code to preformat phone numbers, etc.
       }
    
    return true;
    }

    I think the next thing I’ll try is adding a placeholder to the template and using the &$templates reference to preset that. But this seemed as if it might indicate a need to revisit the logic of pre-parsing field values. Or am I just confused?
      "Things are not what they appear to be; nor are they otherwise." - Buddha

      "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

      Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
      • 33372
      • 1,611 Posts
      OK well this alternative method seems to work:
      function preFormParse(&$fields,&$templates){
      
         global $modx;
         $evt=&$modx->event;
         $validFormId=($evt->params['formid']==$_POST['formid']);
         $isPostBack=($validFormId && count($_POST)>0);
         
         if (!$isPostBack) { // Check for NOT postback, since we only want to prepopulate an empty form
            $defaultmessage=$modx->getChunk('sendLetterText');
            $templates['tpl']=str_replace('[+defaultmessage+]', $defaultmessage, $templates['tpl'] );
         }
         else { // the form has been posted, so pre-process any data here
            // code to preformat phone numbers, etc.
         }
      
      return true;
      }

      So I think my personal problem is solved (well, this one anyway)...
        "Things are not what they appear to be; nor are they otherwise." - Buddha

        "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

        Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options