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.

Hacking the member templates to allow radio btns and checkboxes for custom profile fields

September 06, 2007 6:20pm

Subscribe [9]
  • #31 / Nov 27, 2007 10:48am

    Ryan M.

    1511 posts

    Right, I cannot wait to give that module a try. I thought that project died, but I’m glad to see that it has been released!

  • #32 / Jun 03, 2009 1:25pm

    Todd D.

    460 posts

    I’ll go ahead and resurrect this thread from the dead with a quick two questions. Does this hack still work with 1.6.7?

    AND is there a better approach here in 2009?

  • #33 / Jun 03, 2009 1:41pm

    nathanpitman

    531 posts

    Yes, don’t hack anything… buy the Solspace User Module - makes life so much easier! 😊

  • #34 / Jun 03, 2009 1:52pm

    Todd D.

    460 posts

    I am using the Solspace Module… but I do not see a place that I can create custom profile fields for members that are radio buttons or check boxes. Where am I not looking?

  • #35 / Jun 03, 2009 3:17pm

    Ryan M.

    1511 posts

    I can’t say for sure if this still works, but I don’t see why it wouldn’t. Only other approach I can think of would be to make a members weblog with any/all custom fields you want there and related entries there to a member using a member custom field like Leevi’s LG Member List.

  • #36 / Jun 03, 2009 4:47pm

    Todd D.

    460 posts

    Thanks Ryan and Nathan.

    I did figure this out using the User module.

    Create a custom member profile field and choose ‘drop-down list’ as the field type.

    In your custom user templates you can then change this field type to display as radio buttons or checkboxes.

    Radio buttons like this.

    {select_customfieldname}
    <input type="radio" name="customfieldname" value="{value}">{value}</option>
    {/select_customfieldname}

    Checkboxes like this.

    {select_customfieldname}
    <input type="checkbox" name="customfieldname" value="{value}">{value}</option>
    {/select_customfieldname}

    That seems to be working.

  • #37 / Jun 03, 2009 5:18pm

    Ryan M.

    1511 posts

    Wow, if that works as advertised…nice tip!

  • #38 / Jun 04, 2009 5:16pm

    Todd D.

    460 posts

    Ok, I’m getting into this a bit further.

    When the user returns to this page, I want them to be able to see the entries as checked if they have already set a value.

    I created a custom profile field for reservations. The options they can choose are…

    None
    Recommended
    Required

    For the radio button I’m using this…

    {select_reservations}
    <input type="radio" name="reservations" value="{value}"{if reservations == "{value}"} checked="checked"{/if}>{value}</option>
    
    {/select_reservations}

    I can confirm this works fine and shows the correct radio button as checked when returning to the page.

    However, I’m having trouble with the check box approach. I created a custom profile field called cc_accepted with the following values available.

    American Express
    Discover
    MasterCard
    Visa

    The code I’m using is nearly the same…

    {select_cc_accepted}
    <input type="checkbox" name="cc_accepted" value="{value}"{if cc_accepted == "{value}"} checked="checked"{/if}>{value}</option>
    
    {/select_cc_accepted}

    The list shows fine and I can select a cc and the value is stored when I submit. However, if I select two or more check boxes and submit and then call back the field with {cc_accepted} in the template, I only get the checkbox that is checked furthest down the list.

    So from the front end… they see.

    Choose the credit card(s) you accept below.

    Amercian Express
    Discover
    MasterCard
    Visa

    If they select American Express AND Discover… the only value that is returned with {cc_accepted} is the Discover value. If they select American Express and MasterCard, the only value returned by {cc_accepted} is MasterCard. If they choose ONLY Discover, then Discover will show. If I select more than one… only the box checked furthest down the list shows.

    What am I missing here?

    Thanks in advance!

  • #39 / Jun 05, 2009 1:57pm

    Ryan M.

    1511 posts

    Todd, on the Solspace docs page for Freeform, they show how a checkbox should look in the code - and I’m sure it’s the same sort of thing here. Their example is:

    <input type="checkbox" name="mailinglist[]" value="default">

    Note the brackets there. Your code may need to look like:

    {select_cc_accepted}
    <input type="checkbox" name="cc_accepted[]" value="{value}"{if cc_accepted == "{value}"} checked="checked"{/if}>{value}</option>
    
    {/select_cc_accepted}

    I’m not sure how different the if statement would look, but that tip might get you in the right direction.

  • #40 / Jun 05, 2009 2:12pm

    Todd D.

    460 posts

    Yes, Ryan, Kelsey at Solspace also sent me an email on this.

    That code does fix the value issue so that multiple values can be stored. Now I’m trying to figure out how to display a check box as selected when a person returns to that page after submitting.

    I might have to create some if statements with the actual values stored in the drop-down list. I’m still looking into and when I figure it out… I will post the results here.

    Thanks for your help!

  • #41 / Jun 05, 2009 6:00pm

    Todd D.

    460 posts

    Ok, Kelsey helped me get this working.

    The correct code for check boxes is as follows…

    {select_cc_accepted}
    <input type="checkbox" name="cc_accepted[]" value="{value}" {checked}>{value}</option>
    
    {/select_cc_accepted}

    This works perfectly. When revisiting the page, the check box is selected according to the values entered previously.

    Thanks to everyone for all the help!

  • #42 / Aug 29, 2009 7:25am

    outline4

    271 posts

    hi there,

    the above code works well if you have multiple values in you custom profil fields.

    IF, for some reason, you want to have only “yes” or “no” as custom field values you can take the following code example:

    <input type="hidden" name="custom_fieldname" value="" />
    <input type="checkbox" name="custom_fieldname" value="yes" {if custom_fieldname == "yes"}checked="checked"{/if} />

    this code example works well for drop down menus:

    <select name="custom_fieldname"> 
            {select_custom_fieldname} 
                <option value="{value}" {selected}>{value}</option> 
            {/select_custom_fieldname} 
    </select>

    maybe this helps someone else, as it did help me.
    p.s. I’m using solspace’s user module.
    cheers
    stefan

  • #43 / Feb 18, 2010 9:41am

    Milo Creative

    20 posts

    Great, this works very well.

    Now, how can I run conditionals to check that an option has been selected, when there are multiple selections?
    Using Todd’s example: after I picked American Express and Visa, how do I then achieve the following (in “mock” EE code)

    {if Visa is selected} then display some content {/if}


    Using the Query module?

  • #44 / Feb 18, 2010 11:57am

    Milo Creative

    20 posts

    IF, for some reason, you want to have only “yes” or “no” as custom field values you can take the following code example:

    <input type="hidden" name="custom_fieldname" value="" />
    <input type="checkbox" name="custom_fieldname" value="yes" {if custom_fieldname == "yes"}checked="checked"{/if} />

     

    I think the code above should be:

    <input type="hidden" name="custom_fieldname" value="no" />
    <input type="checkbox" name="custom_fieldname" value="yes" {if custom_fieldname == "yes"}checked="checked"{/if}>Bla bla</input>

    The value “no” should be assigned to the hidden input field, otherwise leaving it blank will prevent EE from storing the correct option.

    Hope this helps..

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases