Unique unless blank

Hey All,

I would like to make it so certain profile fields on the Join Form and Profile editor are Unique unless they are blank.

Eg.

Facebook ID

User 1 tries to set it as 123456789 but this is used by another member so they system says this id is already is in use.

User 2 goes to edit their profile and leaves Facebook ID blank so they system lets them save the form.

 

Currently if user 2 tries to save their profile with a blank Facebook ID is show's the "Non-Unique" error.

how can i do this?

~~Mike ~~ This Signature is missing something :(
Quote · 8 Jul 2014

Not easy. There is no way to do it in the builders. You will have to modify code.

Edit inc\classes\BxDolProfileFields.php

Look for this at about line 361

    function checkPostValueForUnique( $aItem, $mValue, $iHuman, $iProfileID )
    {
        global $logged;

        if( !$aItem['Unique'] )
            return true;


Add the following under it.

Now this is where it gets tricky. If you want to do the unique check only on values that are not empty for any profile field that is set to unique then use use this code.

        if($GLOBALS['MySQL']->escape($mValue) == '') return true;

However if you only want to allow blank values on certain fields that are set to unique then it gets more complicated. For example to allow my facebook connect profile field to be blank use this.

        if($aItem['Name'] == 'dbcsFacebookProfile' && $GLOBALS['MySQL']->escape($mValue) == '') return true;

You will need to add another line like that one for each field you want to allow to be blank. But you cannot use the field caption. You must know the actual profile field name as it is set in the Profiles table. In the case of my facebook connect module that is dbcsFacebookProfile

https://www.deanbassett.com
Quote · 8 Jul 2014
 
 
Below is the legacy version of the Boonex site, maintained for Dolphin.Pro 7.x support.
The new Dolphin solution is powered by UNA Community Management System.