We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39977
    • 11 Posts
    I agree with the above examples. Extended field are easy to manipulate natively. I have used examples from this forum and on answers posted on Stack overflow to do many things with extended profile fields.

    They are also useful to send to external Databases and/or receive sync information back and store in extended fields. Every time you add registration fields they show up in extended fields. You can suppress that, or delete those later, or populate the values of those later, dynamically. Good technique of each user type required differing additional fields. Also good if you want the user to use update registration later to fill in more information not queried during registration (to keep that form small and friendly). So if you create hidden fields during registration, you can manage those later.

    Good for First Name - Last Name as suggested above and tracking external repositories. Good for passing passwords back to other encryption schema and then removing. Good for managing redirection by group by letting the user identify himself with a pulldown selection during registration that provides variant record additional questions for the registering user to fill out. So you can extend Modx profiles or supplement them or tie it into other databases... dealers choice.

    Here is a Login registration Prehook and Posthook I am using for registration that does all of the above mentioned techniques with profile extendedfields:

    <?php
    $fullname = $hook->getValue('firstname').' '.$hook->getValue('lastname');
    $hook->setValue('fullname',$fullname);
    $tpwd = $hook->getValue('password');
    $hook->setValue('tpwd',$tpwd);
    return true;



    <?php
    $userName = $hook->getValue('username');
    $user = $modx->getObject('modUser', array('username'=>$userName));

    $mygroupname = $hook->getValue('mygroup');
    $user->joinGroup($mygroupname);
    $user->save();

    $dontremove = array();
    $itemstoremove = array('tpwd','myhoteltime', 'myvantime', 'myemployeelist', 'mycompanyname', 'mydelivery');

    $profile = $user->getOne('Profile');
    $extendedFields = $profile->get('extended');
    $userArray = array_merge($user->toArray(),$profile->toArray());


    if ($mygroupname == 'Hotel') {
    include_once("assets/php/lib/hotellib.php");
    $hotelid = AddNewHotel($userArray);
    $extendedFields['hotelid'] = $hotelid;
    array_push($dontremove, 'myhoteltime');
    }
    elseif ($mygroupname == 'Merchant') {
    include_once("assets/php/lib/pricelib.php");
    $merchantid = AddNewMerchant($userArray);
    $extendedFields['merchantid'] = $merchantid;
    array_push($dontremove, 'myvantime');
    }
    elseif ($mygroupname == 'Corporation') {
    include_once("assets/php/lib/buslib.php");
    $compid = AddNewCompany($userArray);
    $extendedFields['compid'] = $compid;
    array_push($dontremove, 'myemployeelist');
    }
    elseif ($mygroupname == 'Employee') {
    include_once("assets/php/lib/buslib.php");
    $employid = AddNewEmployee($userArray);
    $extendedFields['employid'] = $employid;
    array_push($dontremove, 'mycompanyname');
    }
    elseif ($mygroupname == 'Consumer') {
    //include_once("assets/php/lib/conslib.php");
    //$consumid = AddNewConsumer($userArray);
    //$extendedFields['consumid'] = $consumid;
    //array_push($dontremove, 'mydelivery');
    }

    for($k = 0; $k < count($itemstoremove); $k++) {
    if(!(in_array($itemstoremove[$k], $dontremove))) {
    unset($extendedFields[$itemstoremove[$k]]);
    }
    }

    $profile->set('extended', $extendedFields);
    $profile->save();

    return true;