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

    I'm new to MODX - and I think you're gonna see me around here quite often.

    We're currently working on a form which is doing several things at the same time. Among other things the user can subscribe to a newsletter. We are using FormIt (2.0.3) and all is well. Except, we are trying to have a conditional hook, as such:

    &hooks=`recaptcha,spam,email[[+rdoSubscribe:neq=`No`:then=`,mChimpXSubscribe`:else=``]],redirect`

    We can't get the output filter to work (tried with If Package as well - no luck).

    In the email itself, [[+rdoSubscribe]] is output as Yes or No as expected. The radio buttons in the template look as such:

    <input type="radio" name="rdoSubscribe" id="rdoSubscribeYes" value="Yes" [[!+fi.rdoSubscribe:FormItIsChecked=`Yes`]] />Yes
    <input type="radio" name="rdoSubscribe" id="rdoSubscribeNo" value="No" checked="checked" [[!+fi.rdoSubscribe:FormItIsChecked=`No`]] />No

    Any idea how to have a conditional hook based on a radiobutton. That would be really helpful.

    Thank in advance.
    adrian

    This question has been answered by Bruno17. See the first response.

      • 4172
      • 5,888 Posts
      Quote from: elgrandeadi at Feb 16, 2012, 07:07 AM
      Hi all,

      I'm new to MODX - and I think you're gonna see me around here quite often.

      We're currently working on a form which is doing several things at the same time. Among other things the user can subscribe to a newsletter. We are using FormIt (2.0.3) and all is well. Except, we are trying to have a conditional hook, as such:

      &hooks=`recaptcha,spam,email[[+rdoSubscribe:neq=`No`:then=`,mChimpXSubscribe`:else=``]],redirect` 


      We can't get the output filter to work (tried with If Package as well - no luck).

      In the email itself,
      [[+rdoSubscribe]] 
      is output as Yes or No as expected. The radio buttons in the template look as such:

      <input type="radio" name="rdoSubscribe" id="rdoSubscribeYes" value="Yes" [[!+fi.rdoSubscribe:FormItIsChecked=`Yes`]] />Yes
      <input type="radio" name="rdoSubscribe" id="rdoSubscribeNo" value="No" checked="checked" [[!+fi.rdoSubscribe:FormItIsChecked=`No`]] />No


      Any idea how to have a conditional hook based on a radiobutton. That would be really helpful.

      Thank in advance.
      adrian

      put the logic into your hook!
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 3749
        • 24,544 Posts
        Rather than rewriting the email hook, you could add another custom hook before the email hook (it could probably be the first hook in the list). Have it return false if the value is no and the email won't be sent. If a hook returns false, the hooks after it won't execute.


        ---------------------------------------------------------------------------------------------------------------
        PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
        MODX info for everyone: http://bobsguides.com/modx.html
          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
          • 38677
          • 21 Posts
          Thanks for the answers.

          Bruno17: Yes, that is an option and we get that to work. But essentially we are changing a thrid-party core code, which I am not a fan of.

          BobRay: That's not actually what we need. The email needs to be sent either way. But if the user selects yes to subscribe to the newsletter, we want to execute the mailchimp hook. As Bruno suggests, we can always do the check in the mailchimp snippet and simply return true (i.e. abort) if subscription wasn't selected (for the FormIt package to continue to the redirect). But I dislike core hacks. I'd rather have a condition in the FormIt extra.

          So, the question remains, is it possible and if so how to add a condition in the FormIt extra.

          Thank you.

          Adrian
            • 3749
            • 24,544 Posts
            You could put your custom hook in instead of the mailchimp one, then execute the mailchimp snippet conditionally with $modx->runSnippet().

            The redirect hook should still execute when you return from your snippet (as long as the mailchimp snippet has a return at the end).

            ---------------------------------------------------------------------------------------------------------------
            PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
            MODX info for everyone: http://bobsguides.com/modx.html
              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
            • discuss.answer
              • 4172
              • 5,888 Posts
              you can try this:

              create a snippet 'addSubscribeHook':

              <?php
              return (isset($_REQUEST['rdoSubscribe']) && $_REQUEST['rdoSubscribe'] == 'Yes') ? ',mChimpXSubscribe' : '';


              and use it:

              &hooks=`recaptcha,spam,email[[!addSubscribeHook]],redirect`
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!