Need assistance with adding optional user fields

Kevin B Posted in Component Development 6 years ago

I've made use of the "signupfields" component and figured out how to amend the fields required at signup nice and easily.

I need to add a "Preferences" array, but only on the user fields in the profile page. I don't want it to appear on the signup page. (ie its only optional - and not required for signup)

If I include the "prefs" array in the merge with the "gender" signup fields, it appears on the signup page AND the profile page. But if I split it out, it doesnt seem to appear anywhere. And I think that may be because its not a part of the "required" array?

This is in the init section:

    ossn_add_hook('user', 'signup:fields', 'signup_fields');
    ossn_add_hook('user', 'default:fields', 'signup_fields');
    ossn_add_hook('user', 'default:fields', 'prefs_fields');

This is the Gender function that works perfectly:

function signup_fields($hook, $type, $val, $params){
    $toremove           = array(
            "gender"
    );
    $return             = ossn_remove_field_from_fields($toremove, $val);

        $fields             = array();
        $fields['gender'] =  
        array(
                'checkbox' => array(
                        array(
                                'name' => 'gender',
                                'options' => array(
                                        'individual' => ossn_print('com:prefs:individual'),
                                        'couple' => ossn_print('com:prefs:couple'),
                                        'business' => ossn_print('com:prefs:business'))
                        )
                )               
        );              
    return array_merge($return, $fields);
}

And this is the code that doesn't work:

function prefs_fields($hook, $type, $val, $params){
        $fields             = array();
        $fields['prefs'] =  
        array(
                'checkbox' => array(
                        array(
                                'name' => 'prefs',
                                'options' => array(
                                '160' => ossn_print('com:prefs:160'),      
                                '161' => ossn_print('com:prefs:161'),      
                                '162' => ossn_print('com:prefs:162'),      
                                '163' => ossn_print('com:prefs:163'),      
                                '164' => ossn_print('com:prefs:164'))
                        )
                )               
        );              
    return array_merge($return, $fields);
}

Do I need to extend the ossnuser or hook this in somewhere else perhaps?

Any thoughts/suggestions gratefully accepted :)

Thanks
kev

Replies
Indonesian Arsalan Shah Replied 6 years ago

Hi, i suggest you to upload code to http://github.com/ for development, so we can take a look into it

gb Kevin B Replied 6 years ago

ok thanks Malik. Ive already seen the signup component - that's what this was based on. I've just gone one step further.

And regards the commercial components - that's good to know thank you. However, I have written the whole component myself and im pretty sure its just one line of code that needs tweaking.

There are LOADS of components I intend to purchase, and also upgrade to Premium once I establish a community - but for the moment I need to launch this without a budget. If I had the budget i'd just buy the premium version now and have done with it! :D

I've added a location field with a dropdown to choose towns/countries too, it creates the database entry but the value is still blank. I'm sure its just one little tweak and one experienced developer will be able to solve it in seconds :D

Thanks
Kev

gb Kevin B Replied 6 years ago

Sorry, link is case sensitive. New link:
Swing3rsPrefs Component

If anybody is able to shed some light on the lack of data being written to the database that'd be much appreciated :)

Ta

pk Malik Umer Farooq Replied 6 years ago

the link you provide for component is broken
upload your code to GitHub and provide more better

gb Kevin B Replied 6 years ago

Thanks Malik.

My component is looking better. It allows me to specify fields that appear on the signup page, as well as optional fields that only appear on the profile edit page now. I think this could be a component that would benefit the community so i'll look to release it once complete.

I have one little snag though, the new fields appear on the profile edit page, but when I post them, they don't save in the database? If I look at the POST data in the browser, its definitely posting the correct data, and there is a blank entry being added to the entities table, but it doesn't contain any data.

I'd be grateful if somebody could help me with this bit - all I need is for it to save to the sql table, then the component is finished :)

I have uploaded the component here: Swing3rsPrefs Component