Show/hide fields on Profile Form based on subscription

Discussion in 'Customization & add-ons' started by awa_la, Jul 24, 2013.

  1. awa_la

    awa_la New Member

    Joined:
    May 8, 2009
    Messages:
    19
    Hello,

    What I'm really looking to do is create a separate, secondary profile form for certain subscription levels, as described here: Add an additional Profile Form.

    Until that's ready, does anyone know if there is a way to set conditionals for the Edit Profile page so that certain fields are only displayed if a user has a specific product? e.g. A bio text field is visible/editable for Premier members, but no one else.

    Thanks,
    Scott
  2. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    Dear Scott,

    Unfortunately it is not possible right now but in next release we introduce new event Am_Event::SAVED_FORM_GET_BRICKS. This event allow to modify profile form based on current logged in user easily. The necessary code can be located in site.php (http://www.amember.com/docs/Site.php_file) so you will not need to care about it during upgrade.

    Here is example of code to hide Name brick based on subscription status:
    PHP:
    Am_Di::getInstance()->hook->add(Am_Event::SAVED_FORM_GET_BRICKS'siteGetBricks');
     
    function 
    siteGetBricks(Am_Event $event)
    {
        if (
    $event->getType() == SavedForm::T_PROFILE) {
            
    $bricks $event->getReturn();
            
    $user Am_Di::getInstance()->user;
            if ( !
    in_array(1$user->getActiveProductIds()) ) { //remove brick if user has not access to product with id 1
                
    foreach ($bricks as $k => $brick) {
                    
    /* @var $brick Am_Form_Brick */
                    
    if ($brick->getName() == 'Name') {
                        unset(
    $bricks[$k]);
                    }
                }
            }
            
    $event->setReturn($bricks);
        }
    }
  3. awa_la

    awa_la New Member

    Joined:
    May 8, 2009
    Messages:
    19
    Great. Thank you so much.
  4. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    You are welcome! Please note this approach will be possible only after next release. In case you can not wait until next release and need to do it in current version please contact us in helpdesk and refer to this ticket. I will help you with it.

Share This Page