2

I have been over the docs and still fall short on this one.

I have a form where customers can dynamically add referrals to notify. I just can't get the email to send.

Here is my freeform code:

        {exp:freeform:form 
            secure_return="yes" 
            collection="Loyalty Rewards Referrals" 
            required="loyalty_customer_number|loyalty_customer_name|loyalty_referral_name|loyalty_referral_email" 
            form_name="referral_form" 
            form_id="referral_form" 
            template="loyalty_rewards_referral_notice" 
            return="/loyalty/thanks" 
            recipients="yes" 
            recipient_template="loyalty_rewards_referral_notice_email" 
            require_ip="yes" 
        }

I have tried a few different things, but here is the last bit:

            <input class="form_field" type="text" name="loyalty_customer_number" id="loyalty_customer_number"  />
            <input class="form_field" type="text" name="loyalty_customer_name" id="loyalty_customer_name" />
            <input class="form_field" type="text" name="loyalty_referral_name" id="loyalty_referral_name" />
            <input class="form_field" type="text" name="loyalty_referral_email" id="loyalty_referral_email" />
            <input class="form_field" type="text" name="recipient_email_user[]" id="recipient_email_user[]" />

The form itself is hidden and I do some backend validating, during which I add the following prior to submitting:

    //  Create the needed fields in the form
    for (i = 0; i < combinedReferrals.length; ++i) {
        $('<input class="form_field" type="text" name="recipient' + i + '" value="' + combinedReferrals[i] + '" />').insertAfter('.form_field:last');
    }

Which adds the fields for the dynamic referrals in the format of:

<input class="form_field" type="text" name="recipient1" value="Brian|[email protected]" />
<input class="form_field" type="text" name="recipient2" value="Joe|[email protected]" />

What the heck am I doing wrong here?

* EDIT *

Entire freeform code here:

        {exp:freeform:form 
            secure_return="yes" 
            collection="Loyalty Rewards Referrals" 
            required="loyalty_customer_number|loyalty_customer_name" 
            form_name="referral_form" 
            form_id="referral_form" 
            require_ip="yes" 
            template="loyalty_rewards_referral_notice" 
            notify="[email protected]" 
            return="/loyalty/thanks" 
            recipient_user_input="yes" 
            recipient_user_limit="1" 
            recipient_user_template="loyalty_rewards_referral_notice_email" 
        }
            <input class="form_field" type="text" name="loyalty_customer_number" id="loyalty_customer_number"  />
            <input class="form_field" type="text" name="loyalty_customer_name" id="loyalty_customer_name" />
            <input class="form_field" type="text" name="loyalty_referral_name" id="loyalty_referral_name" />
            <input class="form_field" type="text" name="loyalty_referral_email" id="loyalty_referral_email" />
        {/exp:freeform:form}

Then prior to submit, I loop through an array of entries and populate the following:

    //  Create the needed fields in the form
    for (i = 0; i < combinedReferrals.length; ++i) {
        //$('<input class="form_field" type="text" name="recipient' + i + '" value="' + combinedReferrals[i] + '" />').insertAfter('.form_field:last');
        $('<input class="form_field" type="checkbox" name="recipient_email_user[]" value="' + combinedReferrals[i] + '" checked />').insertAfter('.form_field:last');
    }

Where 'combinedReferrals[i]' is 'Brian|[email protected]'.

* EDIT *

I have the emails sending now using the following code:

        {exp:freeform:form 
            form_name="referral_form" 
            form_id="referral_form" 
            notify="[email protected]" 
            require_ip="yes" 
            secure_return="yes" 
            collection="Loyalty Rewards Referrals" 
            required="loyalty_customer_number|loyalty_customer_name" 
            return="/loyalty/thanks" 
            recipients="yes" 
            recipient_limit="10" 
            recipient_template="loyalty_rewards_referral_notice_email" 
        }
            <!-- Customer Fields -->
            <input class="form_field" type="text" name="loyalty_customer_number" id="loyalty_customer_number"  />
            <input class="form_field" type="text" name="loyalty_customer_name" id="loyalty_customer_name" />

            <!-- Referral Fields -->
            <!-- Limit 10 -->

            <!-- FreeForm Data -->
            <input class="form_field" type="text" name="loyalty_referral_name" id="loyalty_referral_name" />
            <input class="form_field" type="text" name="loyalty_referral_email" id="loyalty_referral_email" />
        {/exp:freeform:form}

Then the following is writing the values prior to submission:

    //  Create the needed fields in the form
    var splitValue;
    for (i = 0; i < combinedReferrals.length; ++i) {
        //  Split the result
        splitValue = combinedReferrals[i].toString().split("|");

        //  Populate the form
        $('<input class="form_field" type="text" name="recipient_name[]" value="' + splitValue[0] + '" />').insertAfter('.form_field:last');
        $('<input class="form_field" type="text" name="recipient_email[]" value="' + splitValue[1] + '" />').insertAfter('.form_field:last');
    }

Each email is sent to each recipient as it should. However, they want to use the recipient NAME field to personalize the email sent. If I try to use {recipient_name} I get nothing.

Is there a way to achieve this?

5
  • What does "I just can't get the email to send." mean exactly? Are the entries added to the database? Do you get an error? What? Also what version of FreeForm are you using?
    – AllInOne
    Commented Jan 9, 2014 at 23:31
  • I've been looking through this example: expressionengine.stackexchange.com/questions/12734/… When I say I can't get an email to send, I mean a recipient email. The notification email triggers, but not the recipient emails. This happens even if I "hard code" the fields with values. I am updating my entry above to show current code.
    – W3bGuy
    Commented Jan 10, 2014 at 15:18
  • And what version of FreeForm are you using please?
    – AllInOne
    Commented Jan 10, 2014 at 20:42
  • This might be a javascript issue now. When you inspect the html (with Chrome or Safari inspector) do you see the expected value for recipient_name in your dynamic input field?
    – AllInOne
    Commented Jan 10, 2014 at 20:55
  • FreeForm 3x... I see the fields as they should be. In order to process them in this fashion, they are in arrays. From the docs, I gathered that the array is how to accumulate the multiple email addresses. However, if I do this with the names, it doesn't break them out. Instead, it displays them all as a comma separated list.
    – W3bGuy
    Commented Jan 10, 2014 at 21:04

1 Answer 1

3

Not sure this approach is going to work.

FreeForm expects you to define recipient1 and recipient2 as a parameter of the exp:freeform:form tag, they are then encoded on the server side and the html source only shows a hashed value for the recipient, not the value you are inserting dynamically.

If the method you described here were to be permitted then it would be simple to hijack the form to send email to anyone and it would be rife for abuse by spammers.

Solspace's solution to "tell a friend" and potentially what you want to do is the recipient_user_input="yes"value in the exp:freeform:form tag. You have this value as an input but not in the exp:freeform:form tag. I've read the docs a couple of times and I don't think that you can use recipient1...2...3... with this approach, but I could be wrong.

Take a look at the tell-a-friend example in the docs.

I think you'll need to specify recipient_user_template instead of recipient_template. You'll probably want/need to set recipient_user_limit as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.