We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • Jason Sonderman Reply #1, 10 years ago
    I have a contact form that will go to a catchall sales email, but they want a copy sent to the "local" rep for the country that is selected in the form.

    I have the Country<->Contact info set up in a simple MIGX TV.

    Once I match the $fields['fldxx']['fld_country_value'] to an entry in the TV, and have the additional email address, how do I add it to the email send that mxfb is getting ready to do?

    It looks like its owner property is an id number (these extra email addresses are not in the modx system). Is there a way to append it with a string email address?

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

    • Hey Jason,

      You can use the emailOwners property/parameter to send to email address not defined in the system. That can be passed in the snippet call or also set via the hook post processing if its actually a look up after selection in the form.

      Are you using the TV to make a selection list in the form or is this assigned to the page on-load? Just need to understand how your integrating the TV with the form processing/display.

      Cheers
        Evo Revo // Ubuntu, CentOS, Win // Apache 2x, Lighttp (Lighty)
        Visit CharlesMx.com for latest news and status updates.
      • Jason Sonderman Reply #3, 10 years ago
        The tv of the contacts doesn't have any relation to the form until submission. Once the form is submitted, I have a hook to check if an email address is assigned to the country value from the country select box (country select is a custom field type that is built using a chunk... thanks for that).

        so, if no match is found, the hook just returns true without setting any hook->properties.

        This is my first second attempt at doing this in the hook:
        $fieldVals = $hook->getProperties();
        $emailOwners = explode(',',$fieldVals['emailOwners']);
        $emailOwners[]='[email protected]';
        $hook->setProperties('emailOwners',implode(',',$emailOwners));
        

        This is only the email setting part. I am finishing the Formvalue-TV check this morning.

        Is this the way to add addresses to the emailOwners property of the hook and send it along? [ed. note: dvstudiosinc last edited this post 10 years ago.]
        • Jason Sonderman Reply #4, 10 years ago
          Playing around with the snippet more, so here is the new code:

          //get the emailOwners property and explode it into an array. Is there ever a value in this for a hook?
          $emailOwners = explode(',',$hook->getProperty('emailOwners'));
          
          //Add addresses
          $emailOwners[]='[email protected]';
          $emailOwners[]='[email protected]';
          
          //set the property of the hook to the new string by exploding the array
          $hook->setProperty('emailOwners',implode(',',$emailOwners));
          
          //tell mxfb that this script has run
          return true;
          


          Check the log, the emailOwners property in the hook is being set to the new addresses, but the mxfb class is not receiving it.

          (The area where I am adding two items to the $emailOwners array is just a test. This will be where I iterate through the Country Contact TV array for matches)

          Am I missing a step to actually update the $hook object for the mxfb class?
          • Are you calling the snippet in the preHooks parameter? If not try with the preHooks parameter.

            I need to work out some on the processing order for the post hooks. The root is that the hook processor is called after the email sends happen and the form data is saved, thus ensuring it only comes after a successful submission. I'll work on clarification on this in the documentation as well.

            Hope that helps.

            Cheers



              Evo Revo // Ubuntu, CentOS, Win // Apache 2x, Lighttp (Lighty)
              Visit CharlesMx.com for latest news and status updates.
            • Jason Sonderman Reply #6, 10 years ago
              well prehook isnt going to work since the country value isnt set until the form is submitted.
              i set up another mailsend process in the hook to send the email. just have to define a different tpl since i cant see a way to access the mxfb placeholders at this stage of the form process
              • discuss.answer
                the preHook will process after post, which will set the values you are looking for in this use case. Hit me up on IM.

                Cheers
                  Evo Revo // Ubuntu, CentOS, Win // Apache 2x, Lighttp (Lighty)
                  Visit CharlesMx.com for latest news and status updates.
                • Jason Sonderman Reply #8, 10 years ago
                  To break this out, since it conflicts whats in the online documentation:

                  a PreHook fires BEFORE the form is rendered and AFTER the submit action is registered but BEFORE mxfb processes the submission
                  and a Hook fires AFTER a successful submission/email happens from mxfb

                  The rtfm on this has the prehook happening prior to form rendering and it looks like it does both from my error logs. I

                  The preHook does work to add the new email addresses to email owners, though.
                  • Yes, that is the intended method currently. I plan to extended this slightly and have a flag to allow the "hook" to run prior to or after the save which is where the email handler fires. Sorry for the confusion and I'll make the documentation more clear.

                    Cheers

                    Quote from: dvstudiosinc at Apr 18, 2014, 04:15 PM
                    To break this out, since it conflicts whats in the online documentation:

                    a PreHook fires BEFORE the form is rendered and AFTER the submit action is registered but BEFORE mxfb processes the submission
                    and a Hook fires AFTER a successful submission/email happens from mxfb

                    The rtfm on this has the prehook happening prior to form rendering and it looks like it does both from my error logs. I

                    The preHook does work to add the new email addresses to email owners, though.
                      Evo Revo // Ubuntu, CentOS, Win // Apache 2x, Lighttp (Lighty)
                      Visit CharlesMx.com for latest news and status updates.
                    • Jason Sonderman Reply #10, 10 years ago
                      What was the code to use as a hook to send a confirmation email to the sender (the one who fills out the form)?