3

I have a contact form that has a checkbox so the user can choose to also be added to the newsletter subscription with their contact form submission. Basically this just needs to post a value of "y" and the client manually adds them to their mailing list.

The free version of Freeform no longer has a checkbox fieldtype (Freeform 3.x did). Freeform Pro is an awesome addon, but the only added feature I need is the checkbox field type.

Has anyone figured out a way to pass the value of a checkbox field with the free version?

I tried the Freeform Values extension: https://github.com/stovepot/freeform_values.ee_addon but I wasn't able to get it to work at all - and there is no support for it (bummer). Basically the tag I used {freeform:value:optin_check} shows up in the html output instead of a value.

I thought maybe I could take the value of the checkbox and pass it to a hidden text field, something like this:

<input type="checkbox" id="optin_check" name="optin_check" value="Yes">
<input type="hidden" id="optin" name="optin" value="">

What I tried with the above extension:

<input type="checkbox" id="optin_check" name="optin_check" value="Yes">
<input type="hidden" id="optin" name="optin" value="{freeform:value:optin_check}">

Any ideas on how I could get something like this to work?

Complete Freeform code in my template:

{exp:freeform:form
    collection="Contact"
    return="/contact/thanks"
    inline_errors="yes"
    require_captcha="yes" 
    inline_error_return="contact/error"
    admin_notify="[email protected]"
    template="contact_us"
    form:id="contact-us"    
}

    <p>
        <label for="first_name" class="left">First Name<br>
            <input type="text" value="" name="first_name" id="first_name">
        </label>
        
        <label for="last_name">Last Name<br>
            <input type="text" value="" name="last_name" id="last_name">
        </label>
    </p>
            
    <p>
        <label for="email" class="left">Email<br>
            <input type="email" value="" name="email" id="email">
        </label>
        
        <label for="confirm_email">Confirm Email<br>
            <input type="email" value="" name="confirm_email" id="confirm_email">
        </label>    
    </p>
            
    <p>
        <label for="user_message">Message<br>
            <textarea rows="10" cols="20" id="user_message" name="user_message">
            </textarea>
        </label>
    </p>
    
    <p class="checkbox left">
        <input type="checkbox" checked="checked" name="optin_check[]" value="Yes">
        <label for="optin_check" class="checker">
            Yes, sign me up to recieve the newsletter!
        </label>
        <input type="hidden" id="optin" name="optin" class="optin" value="">
    </p>
    {if captcha}
    <p class="captcha">
        <label class="long">
        Please answer the security question<span class="required">*</span><br>
        {captcha} &nbsp;&nbsp; <input type="text" name="captcha" id="captcha">
        </label>
    </p>
    {/if}                           
    <p class="left">
        <input type="submit" name="submit" id="submit" value="Submit">
    </p>
        
{/exp:freeform:form}  



And here's a screenshot for the visual: enter image description here

3 Answers 3

2

How about trying this on it's own (without a hidden input field) using the freeform_values addon:

<input type="checkbox" name="optin" value="Y" {if '{freeform:value:optin}' == 'Y'}checked{/if}>

Just be sure that the name of your checkbox field is in fact "optin".

Does that work?

3
  • Aha! Yes that way worked :) I had tried the conditional before but I must have had my syntax wrong or something... because nothing was working, and that's when I started to try using a hidden field. Thanks a bunch! Commented Apr 12, 2013 at 15:24
  • No probs. You were close but it just needed some tweaking. :)
    – Ian Young
    Commented Apr 12, 2013 at 16:32
  • I'm having this exact same problem, but I couldn't get the above to work. What am I missing? @ian @ByteMyPixel <div><label for="optin1"> <span>Get information *</span> <input type="checkbox" id="optin1" name="optin" value="Y" {if '{freeform:value:optin}' == 'Y'}checked{/if}> </label> <label for="optin2"> <span>Conduct research * [Ethical approval received Y/N]</span> <input type="checkbox" id="optin2" name="optin" value="Y" {if '{freeform:value:optin}' == 'Y'}checked{/if}> </label> </div> Commented Dec 20, 2013 at 12:57
1

Try changing:

<input type="checkbox" id="optin_check" name="optin_check" value="Yes">

to :

<input type="checkbox" id="optin_check" name="optin_check[]" value="Yes">
5
  • thanks for helping! Unfortunately that produces the same result... I'm still getting the Freeform Value tag in the output. Commented Apr 11, 2013 at 16:38
  • Can you be more clear with what you are trying to do? Perhaps post code for your complete template...
    – Anna_MediaGirl
    Commented Apr 11, 2013 at 19:58
  • For sure, basically it's just a contact form with a checkbox option to be added to the newsletter subscription. I'll update my question with the full template and a screenshot. Commented Apr 11, 2013 at 22:31
  • What is the name of the freeform checkbox field? You have name="optin_check[]" and name="optin" in your code. Do you need both? Make sure you are adding the [] to the correctly named input field.
    – Anna_MediaGirl
    Commented Apr 12, 2013 at 1:18
  • That's the problem, the free version of Freeform doesn't have a checkbox field, and I didn't really want to purchase the pro version just for a checkbox field. The hidden field, name="optin" is the other field I added to try to pass the checkbox value to and capture in freeform. Commented Apr 12, 2013 at 14:55
0

I made it work with {freeform:field:my_newsletter} as my_newsletter is the name of the newsletter.

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.