1

I have a FreeMember based registration form where I want to record a users areas of interest at time of registration and also provide a mechanism to edit those interests after registration through a profile edit screen.

The areas of interest are ExpressionEngine categories so I can easily pull them out and display them as a list of checkboxes on the registration and profile edit screens. My question is two fold...

1) How should I approach storing this data in a custom member profile field? Ideally I want this to remain flexible so I’m envisaging storing the data as a a pipe delimited string of category_ids or a JSONified array.

2) How am I best off processing the data, maybe using a bespoke extension for FreeMember or using jQuery to process the checkbox states on click and process that data and stuff it into a hidden field, then do the reverse on page load.

Thoughts much appreciated!

2

I've solved this by forking and modding the FreeMember add on. When passed an array type form field (i.e. where you name the field 'field_name[]' and then have multiple inputs by the same name) FreeMember would throw a PHP error. I modified the module to simply detect an array type input and implode it and store is as a pipe delimited string.

Modified FreeMember model: https://github.com/nathanpitman/freemember/commit/e04a3142981281c125fb1417d8f9205b34c882e7

When returning the data I was able to use the PHP String Fun plug-in to parse the pipe delimited list and compare it the category_ids in my channel:categories loop to 'check' the correct checkboxes. :)

Example template code to check categories based on a pipe delimited string is a custom member field:

<ul>
    {exp:channel:categories channel="content" parent_only="yes" style="linear"}
    <li><label for="Cat_{category_id}"><input type="checkbox" id="Cat_{category_id}" name="member_interests[]" value="{category_id}"{if "{exp:phpstringfun function='substr_count' par1='{category_id}'}{member_interests}{/exp:phpstringfun}" == "1"} checked="checked"{/if}> {category_name}</label></li>
    {/exp:channel:categories}
</ul>
0

I think as you have figured out, Freemember doesn't support this natively. Freemember is a simple solution, and is only really designed to work with the built in EE member field types. That said, you could definitely modify Freemember to suit your needs.

To be honest, with complex requirements like this I would look into a more full-featured solution such as Zoo Visitor which allows any custom member field types using regular EE channel entries, rather than trying to modify Freemember to do it.

1
  • 1
    Thanks Adrian. The modification I made to FreeMember was pretty simple in the end, I just had it catch any array type fields and implode them to a pipe delimited string, previously submitting an array type field when using FreeMember would have caused it to throw a PHP error so it kinda killed two birds with one stone. :) Jun 16 '14 at 7:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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