News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Profile question with multiple checkboxes?

Started by Jade Elizabeth, November 14, 2013, 08:42:45 PM

Previous topic - Next topic

Jade Elizabeth

I wanna have a profile question that can have multiple checkboxes...sort of like a "what are you interested in?" checkbox with say art, music, etc listed after it.

It seems the checkbox option in admin is for one checkbox. Is there a mod or something I can install to make a checkboxes option?
Once proud Documentation Writer and Help Squad Leader | Check out my new adult coloring career: Color With Jade/Patreon.

Arantor

It's for one checkbox. The structure and method of the way it is stored makes storing multiple checkboxes unreliable.

There is also no mod for it.

Jade Elizabeth

Hmm. What do you suggest? I sort of need the data to be stored so I can use it in our stats.

I guess my next best option is select boxes...
Once proud Documentation Writer and Help Squad Leader | Check out my new adult coloring career: Color With Jade/Patreon.

Jade Elizabeth

I just did a select box for now...seems to be all right. Wish I could have a big bunch of checkboxes!
Once proud Documentation Writer and Help Squad Leader | Check out my new adult coloring career: Color With Jade/Patreon.

soderlund

(I hope this necro-bump isn't inappropriate.)

I want to create a mod that achieves this. Like the radiobuttons custom profile field but checkboxes.

You need to store multiple values because several checkboxes can be selected. I figure it should be possible if you store the user's selected values in a comma separated string (and remove any commas before splicing them).


// Profile.php
function loadCustomFields($memID, $area = 'summary')
{
    ...
    $value = $exists ? $user_profile[$memID]['options'][$row['col_name']] : '';
    ...
    // 'checkboxes' is the multiple-choice checkbox custom field.
    if ($row['field_type'] == 'checkboxes')
    {
        // $values are the user's selected checkboxes.
        $values = explode(',', $value);
        $options = explode(',', $row['field_options']);
        foreach ($options as $k => $v)
        {
            // The checkbox is checked if in_array($v, $values).
            ...
        }
    }
    ...
}


(Presumably some other changes are required too.)

Questions

Would this work at all?

Is it possible to create a mod that does this (using an integration hook), or do I have to change the "core" code? Unless I've totally misunderstood how it works, you can override ModifyProfile() but not loadCustomFields() using integration hooks, and therefore it's not possible to create such a mod. Correct?

Thanks in advance.

Jade Elizabeth

It would be fantastic if you could create a mod for it! I hope someone helps you out :D.
Once proud Documentation Writer and Help Squad Leader | Check out my new adult coloring career: Color With Jade/Patreon.

soderlund

Yes. Please help. :-)

I am a bit worried because Arantor has said it's unreliable (in another thread too) and I don't understand why.

Quote from: Arantor on March 24, 2013, 12:11:48 PM
The manual's wrong. It has never worked like that, not since it was first implemented several years ago. You're pretty much the first person to notice.

The code doesn't even support multiple selection. I know this for a fact because when I wrote the helpdesk used on this site, we started off using a similar template for the custom fields - and I specifically had to add a ton of code to make multiple selection boxes work. Including the UI code.

Quote from: Arantor on March 24, 2013, 12:22:56 PMSometimes you just want a yes/no option and one of them, and this is what it's for. Doing multi-selection in the current code would be... extremely unreliable.

It seems straightforward to me (just copy the radiobutton code, replace it with checkboxes, make the value comma separated, and sanitize the value before saving it), so I must have missed something.

I'm going to try my solution (edit the stuff in Profile.php and Profile-Modify.php and create a package with modification.xml). But I only started using SMF this week so any help is greatly appreciated. I'll release it under the ISC license when it's done -- assuming it can be done.

Jade Elizabeth

I would give it a go. Look at how board moderators are stored, and other areas where multiple values are stores too. I think there's a bunch in the board permissions and who sees what board. Smileys/board icons....I reckon if you can mimic that, then you should be right.

I would give it a go, release it, and then through testing we'll all know when/where it screws up and you'll know then ha ha.
Once proud Documentation Writer and Help Squad Leader | Check out my new adult coloring career: Color With Jade/Patreon.

Jade Elizabeth

Really sorry you haven't had a more helpful response yet. I have been asking around. Have you figured it out or made any progress? :)
Once proud Documentation Writer and Help Squad Leader | Check out my new adult coloring career: Color With Jade/Patreon.

Colin

Just making a post to remind myself to answer this when I finish moving in 2 days. Really appreciate your patience
"If everybody is thinking alike, then somebody is not thinking." - Gen. George S. Patton Jr.

Colin

soderlund

I started doing something else with higher priority. Not because I think this is impossible, just lack of time. I will look into this properly when the other thing is done. I'll post an update when I've figured it out or given up. ;)

I've gotten them to show up and made it possible to add them the same way you add radio buttons (required more code changes than I expected), but they don't persist when you save them. Probably some simple error.

Jade Elizabeth

Is it that they don't persist or you're having issues storing them/retrieving the info?
Once proud Documentation Writer and Help Squad Leader | Check out my new adult coloring career: Color With Jade/Patreon.

Advertisement: