We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 35756
    • 166 Posts
    Hi there!

    Hopefully this is my last question for this project.

    I have several plaeholders in my mails that get sent to the admin and the form-submitter on validation success.

    [[+option1:notempty=`[[+option1]]<br />`]]
    [[+option2:notempty=`[[+option2]]<br />`]]
    [[+option3:notempty=`[[+option3]]<br />`]]
    [[+option4:notempty=`[[+option4]]<br />`]]
    [[+option5:notempty=`[[+option5]]<br />`]]
    [[+option6:notempty=`[[+option6]]<br />`]]
    [[+option7:notempty=`[[+option7]]<br />`]]
    [[+option8:notempty=`[[+option8]]<br />`]]
    [[+option9:notempty=`[[+option9]]<br />`]]
    [[+option10:notempty=`[[+option10]]<br />`]]
    [[+option11:notempty=`[[+option11]]<br />`]]
    [[+option12:notempty=`[[+option12]]<br />`]]


    Afterwards there are several statements implemented in the mails.

    What I want to achieve now is that if option1 or option 2 or option 3 etc. up to option10 is not empty, I want to output a separate text-block in those mails.

    So something like this

    [[+option1:notempty:and:[[+option2:notempty]]:and:[[+option3:notempty]]:and:[[+option4:notempty]]:and:[[+option5:notempty]]:and:[[+option6:notempty]]:and:[[+option7:notempty]]:and:[[+option8:notempty]]:and:[[+option9:notempty]]:and:[[+option10:notempty]]=`separate textblock`]]


    Any way to get this done?
      • 3749
      • 24,544 Posts
      I think you want ":or" rather than ":and." You also should have :else=`` at the end.


      Also, your conditionals above will be faster and more efficient if they take this form:

      [[[[+option1:notempty=`+option1<br />`]]]]
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 35756
        • 166 Posts
        Hi Bob!

        And thanks for you response!

        I tried it like this, but this didn't work as expected:

        [[+option1:notempty:or:[[+option2:notempty]]:or:[[+option3:notempty]]:and:[[+option4:notempty]]:or:[[+option5:notempty]]:or:[[+option6:notempty]]:or:[[+option7:notempty]]:or:[[+option8:notempty]]:or:[[+option9:notempty]]:or:[[+option10:notempty]]=`separate textblock`:else=`2`]]

        I always get the "2" in my confirmation-mails, regardless if option1-10 have been used or not.

        The suggestion

        [[[[+option1:notempty=`+option1
        `]]]]

        didn't work for me either, then I got this in my mails:

        [[+options1
        ]] [[+options2
        ]] [[+options3
        ]] [[+options4
        ]] [[+options5
        ]] [[+options6
        ]] [[+options7
        ]] [[+options8
        ]] [[+options9
        ]] [[+options10
        ]] [[+options11
        ]] [[+options12
        ]] [[]]

          • 3749
          • 24,544 Posts
          Sorry, I didn't notice this before, but conditional output modifiers like 'and' and 'or' need a "then" clause just before the else. http://rtfm.modx.com/revolution/2.x/making-sites-with-modx/customizing-content/input-and-output-filters-%28output-modifiers%29

          I would try using a snippet first (it will be *way* faster if it works). Put the alternate text in a chunk called AltTextBlock. Put this tag where the text block goes.

          [[!TextBlock]]


          Then, create a snippet called TextBlock with this code:


          /* TextBlock snippet */
          
          $optionCount = 12;
          $hasOption = false;
          
          for ($i = 1; $i <= $optionCount; $i++) {
              if (! empty ($modx->getPlaceholder('options' . $i))) {
                  $hasOption = true;
              }
          }
          
          return $hasOption? $modx->getChunk('AltTextBlock') : 'xxxxx' ;


          The 'xxxxx' is for debugging purposes. Change it to '' if everything works.

          Whether it works will depend on how well the tags in the email chunk get processed before sending and whether the placeholders are set at that point, but it's definitely worth a try.



            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 35756
            • 166 Posts
            Sorry for the late reply, and thx for your help again!

            I just tried your snippet-code, but it doesn't seem to work either:

            First I created a new snippet called "EmailTextBlock" with your code above:

            /* EmailTextBlock snippet */
             
            $optionCount = 12;
            $hasOption = false;
             
            for ($i = 1; $i <= $optionCount; $i++) {
                if (! empty ($modx->getPlaceholder('options' . $i))) {
                    $hasOption = true;
                }
            }
             
            return $hasOption? $modx->getChunk('AltTextBlock') : 'xxxxx' ;


            Then I added the snippet-call inside the chunk which gets used for sending the mail:

            [[!EmailTextBlock]]

            Then I submitted the form and received the mail, but in it there is the [[!EmailTextBlock]] within, it doesn't get "rendered".

            After that I realized the line

            return $hasOption? $modx->getChunk('AltTextBlock') : 'xxxxx' ;


            So I thought another chunk calles "AltTextBlock" is needed. SO I created this, filled it with some "lorem ipsum" and submittet the form again; but same result, the snippet-call "[[!EmailTextBlock]]" is inside the mail that got sent.
              • 3749
              • 24,544 Posts
              I'm afraid that means that the non-placeholder tags in the chunk aren't processed. That kind of figures, since the content is being sent by email rather than displayed on the web. You might be able to fix it by adding something like $content = $chunk->process; somewhere in the code that sends the email, but you'd have to find it first.

              What are you using to send the email (Manager built-in code, Subscribe, Register, FormIt)?
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 35756
                • 166 Posts
                thx again Bob for your reply and hint...i'm gonna check it what and where i have to add that the non-placeholders get processed in the chunk.

                I'm using FormIt...i thought this would be clear because I did choose this area to post my question.
                  • 3749
                  • 24,544 Posts
                  Quote from: profilneurotiker at Aug 20, 2014, 05:22 AM

                  I'm using FormIt...i thought this would be clear because I did choose this area to post my question.

                  It would have been if I weren't too lazy to check the area. wink
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting