ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

tag within advanced conditional issue

June 14, 2011 7:55pm

Subscribe [3]
  • #1 / Jun 14, 2011 7:55pm

    ehicks727

    90 posts

    I’m using Freeform and Mailchimp EE extensions and I’m coming across a problem.

    I have a contact form with a checkbox, when if checked, it’s supposed to subscribe them to a MailChimp mailing list.

    When the form redirects to the thank you page, I fire this code in the thank you page.

    {exp:freeform:entries collection="Contact Form" orderby="date" sort="desc" limit="1"} 
    {if subscribe == "Yes"} 
        {exp:mailchimp_ee:subscribe api_key="xxxxxxxxxxxxxxxxxxxxxxxx" list_id="6339acac14" email_address="{email}" double_optin='yes'}
    {/if}
    {/exp:freeform:entries}

    It’s subscribing the users whether the check box is checked or not!

    Is there a better way I can be doing this?

  • #2 / Jun 15, 2011 7:18am

    John Henry Donovan

    12339 posts

    ehicks727,

    We don’t support third-party add-ons I’m afraid but I’m going to move this thread to Community Help where other users may have done similar.

  • #3 / Jun 15, 2011 9:48am

    ehicks727

    90 posts

    ehicks727,

    We don’t support third-party add-ons I’m afraid but I’m going to move this thread to Community Help where other users may have done similar.

    My question was more procedural than a specific question about a third-party app.

    The question was is there a better way to do this so that a tag doesn’t run if I have it surrounded by an if.  Would you like me to put this in generic terms and leave out the reference to Freeform and Mailchimp?  I can do that!  Will I get help then? Sheesh.

  • #4 / Jun 15, 2011 10:00am

    Kernon

    173 posts

    Actually, it might be specific to the add-ons that you are using.  Because, where is the value for subscribe coming from?

    If ‘subscribe’ is a form field that freeform is generating, it isn’t going to have a value until after the form is submitted.  If that is the case, I don’t see how the conditional can be handled (properly parsed) by EE.

  • #5 / Jun 15, 2011 10:27am

    ehicks727

    90 posts

    Actually, it might be specific to the add-ons that you are using.  Because, where is the value for subscribe coming from?

    If ‘subscribe’ is a form field that freeform is generating, it isn’t going to have a value until after the form is submitted.  If that is the case, I don’t see how the conditional can be handled (properly parsed) by EE.

    It shouldn’t matter.  Here, let me put this in generic terms.

    Say I have a channel entry (that way we can avoid talking about Freeform) and it has a field called in_public.

    Then I have a tag called fart.

    If in_public = “yes” then don’t fart.

    It’d look something like this..

    {exp:channel:entries channel="location"}
        {if in_public != "yes"}
            {exp:bodily_functions:fart}
        {/if}
    {/exp:channel:entries}

    Because it seems that EE parses tags before conditionals, I’m ALWAYS going to fart, right?

    So what I’m asking for is if anyone knows a way to make this happen procedurally so that I don’t fart.

    Thanks.

  • #6 / Jun 15, 2011 10:36am

    Kernon

    173 posts

    I’ll readily admit that I may have gotten confused over the specifics of freeform versus abstracting the problem.  But, in your example, I assume that ‘in_public’ is (say) a custom field that has a value which EE “knows” about before it encounters the conditional.

    But does ‘subscribe’ have a value (established by freeform) before the conditional is encountered?

    Because if ‘subscribe’ doesn’t have a value until a user submission, then that case is fundamentally different from the channel entries example (as far as I can see).

  • #7 / Jun 15, 2011 10:45am

    ehicks727

    90 posts

    I’ll readily admit that I may have gotten confused over the specifics of freeform versus abstracting the problem.  But, in your example, I assume that ‘in_public’ is (say) a custom field that has a value which EE “knows” about before it encounters the conditional.

    But does ‘subscribe’ have a value (established by freeform) before the conditional is encountered?

    Because if ‘subscribe’ doesn’t have a value until a user submission, then that case is fundamentally different from the channel entries example (as far as I can see).

    good point.

    The process that happens is that I have a form that has a checkbox where the user clicks to subscribe.  Freeform saves the subscribe field = “yes” then redirects to a thank you page. The thank you page is a template that runs the conditional statement, so I read the latest entry into the Freeform database, if subscribe = yes, then run the Mailchimp process.

    So technically the answer to your question is yes, subscribe does have a value established by Freeform.  That is saved when the user hits submit.

    Where this gets sticky is that after the user hits submit, they get redirected to page that loads the template that runs the conditional statement.

    Is there another procedural way I can handle this??  Can I load subscribe into a session or something??  At this point, I’ll try anything.

  • #8 / Jun 15, 2011 10:54am

    Kernon

    173 posts

    Off the top of my head, I don’t know if there is an easier way, but, yes, you could certainly use a session to store the data.

    See: Session Variables Plugin

  • #9 / Jun 15, 2011 11:01am

    ehicks727

    90 posts

    Off the top of my head, I don’t know if there is an easier way, but, yes, you could certainly use a session to store the data.

    See: Session Variables Plugin

    Well, now that I think about it, loading it into a session won’t do anything because I still have to run a conditional somewhere.

    I think I’m going to have to AJAX this form.

    This parsing order thing with EE is kind of a pain.

    Thanks for your help… if anyone has any other ideas, I’m still asking for help!

  • #10 / Jun 15, 2011 11:11am

    Kernon

    173 posts

    I’m not sure, but you might be able to use something like STASH since it works with conditionals (still might require a session to get the value into stash).

  • #11 / Jun 15, 2011 11:29am

    ehicks727

    90 posts

    I’m not sure, but you might be able to use something like STASH since it works with conditionals (still might require a session to get the value into stash).

    Interesting!  I’ll try it out, thanks!!

  • #12 / Jun 16, 2011 11:32am

    ehicks727

    90 posts

    Ok, so if anyone else stumbles on this with a similar problem, here’s the solution I came up with.

    First of all, there is no way that I can find (even using STASH) to NOT execute a tag inside an advanced conditional.  So I had to come up with another solution.

    So the process that works is to send the submitted form to a template that goes through the Freeform fields, if subscribe = “Yes”, then REDIRECT to a separate template that processes Mailchimp.

    Here’s the code.

    The code snippet in the contact form thank you page template

    {exp:freeform:entries collection="Contact Form" orderby="date" sort="desc" limit="1"} 
        {if subscribe == "Yes"}
            {redirect="/subscribe_thank_you"}
        {/if}
    {/exp:freeform:entries}

    And here’s the code in the subscribe_thank_you template

    {exp:freeform:entries collection="Contact Form" orderby="date" sort="desc" limit="1"} 
        {exp:mailchimp_ee:subscribe api_key="xxxxxxxx" list_id="xxxxxxxx" email_address="{email}" double_optin='yes'}
    {/exp:freeform:entries}
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases