We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32684
    • 1 Posts
    Hi. I’m working on my first ModX site. I have a form: http://cvhs.connectvolunteers.org/volunteer-form/

    I am stuck on the checkboxes. I am using:

    <input name="interest[]" type="checkbox" value="Library" />
    <input name="interest[]" type="checkbox" value="Office" />

    etc.

    I want to email the results. I have no problem grabbing the text and textarea fields, but I’m at a loss for how to put the "interest" array into the email message.

    How do you show the array in the email template?

    /Wendy
      • 11880
      • 1 Posts
      I have the same question.

      I’m thinking the answer has to do with the FormItIsChecked snippet:

      $output = ’’;
      if ($input == $options) {
      $output = ’ checked="checked"’;
      }
      if (strpos($input,’,’) !== false) {
      $input = explode(’,’,$input);
      if (in_array($options,$input)) {
      $output = ’ checked="checked"’;
      }
      }
      return $output;

      I just don’t know PHP well enough to know where to put what. Is this in FormIt’s documentation somewhere? I’m not seeing it.

      Any and all help would be appreciated! Thank you!
        • 4172
        • 5,888 Posts

        because its an array try the placeholders:

        [[+interest.0]]
        [[+interest.1]]


        you can also use a hook-snippet to store the results in a new field.
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
        • I wanted to do something similar but with text input fields, but we won’t have the number of this fields, it can be anything, is those forms that you add more fields, how can I do it?

          Thanks in advance guys!
            ----
            Daniel Melo
          • Here’s a little snippet (hook) I wrote to process the arrays. I am using FormIt 1.5.5 and MODx Revolution 2.1 RC3:

            The fiProcessArrays snippet:
            <?php
            /* 
             * fiProcessArrays formit hook. Processes all values stored as arrays and implodes them.
             * Copyright Oleg Pryadko (websitezen.com) 2011
             * License GPL 2 or later 
            */ 
            $fieldSuffix = $modx->getOption('fipaFieldSuffix',$scriptProperties,'_values');
            $separator = $modx->getOption('fipaValueSeparator',$scriptProperties,', ');
            $allFormFields = $hook->getValues();
            foreach ($allFormFields as $fieldName => $fieldValue) {
              if (is_array($fieldValue)) {
                $imploded = '';
                $count=0;
                foreach ($fieldValue as $value) {
                  if (!empty($value)) {
                    if ($count) {$imploded .= $separator;}
                    $imploded .= $value;
                    $count++;
                  }
                }
                $hook->setValue($fieldName.$fieldSuffix,$imploded);
              }
            }
            return true;
            


            The FormIt call:
            [[!FormIt?
            &hooks=`fiProcessArrays,email`
            &emailTpl=`ContactFormReport`
            &emailTo=`[[++emailsender]]`
            `]]
            


            For each array field (e.g. checkbox field as described above), this snippet sets a new field value made from the field name and a suffix.

            For example, for a favoriteColors[] array, the field value favoriteColors_values and corresponding email placeholder [[+favoriteColors_values]] will be created.
              WebsiteZen.com - MODX and E-Commerce web development in the San Francisco Bay Area
              • 7976
              • 36 Posts
              Thank you Oleg, works as a charm.
                Jack of all Trades and Proud Honda Zoomer owner. Also available on twitter.
                • 17667
                • 108 Posts
                Let me second that thank you to Oleg. You just saved me a huge amount of time.
                • You’re welcome. Glad to help!
                    WebsiteZen.com - MODX and E-Commerce web development in the San Francisco Bay Area
                    • 34183
                    • 23 Posts
                    You can also get the value from FormItRetriever with [[+fi.favoriteColors_values]]
                    • For those that are interested, here is a similar snippet that generates an email report for you (also stored in a placeholder): http://modxcms.com/forums/index.php/topic,64656.html
                        WebsiteZen.com - MODX and E-Commerce web development in the San Francisco Bay Area