admin only field

Discussion in 'Customization & add-ons' started by davidm1, Jan 8, 2016.

  1. davidm1

    davidm1 aMember User & Partner

    Joined:
    May 16, 2006
    Messages:
    4,437
    I'd like to add an admin field so that I can switch on or off certain signup pages.

    Need this:
    1) how to add an admin only field
    2) how to read if that field is 'on'/'off' on a signup page
    3) same as #2 but in site.php

    thanks,

    david
  2. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    In case of you do not add user field to either signup or profile form then only admin can see/edit it.
    So just add new field at aMember CP -> Configuration -> Add User Fields

    You can add two type of fields - SQL and DATA:
    DATA: $user->data()->get('field_name');
    SQL: $user->field_name;

    Do you mind to elaborate on point 2? What do you want to achieve here?
  3. davidm1

    davidm1 aMember User & Partner

    Joined:
    May 16, 2006
    Messages:
    4,437
    these are not user fields- this is so the admin can control if part of a signup form is viewable or not.

    David
  4. jenolan

    jenolan aMember Coder

    Joined:
    Nov 3, 2006
    Messages:
    510
    Ummm ... a plugin with the settings (ie Signup Settings) which has the required settings so you can fiddle them in the ACP problem is that you would need to build a signup template which loads the settings and handles the insertions. This would mean the default brick system would be unusable for the optional sections.
  5. davidm1

    davidm1 aMember User & Partner

    Joined:
    May 16, 2006
    Messages:
    4,437
    should be addable using a site.php edit i would imagine. I just want to add an admin field, and check its status!

    David
  6. jenolan

    jenolan aMember Coder

    Joined:
    Nov 3, 2006
    Messages:
    510
    In site.php
    Code:
    global  $myStuffSwitch;
    $myStuffSwitch = true;
    
    in form;
    Code:
        global  $myStuffSwitch;
        if( $myStuffSwitch )
        {
             /// Added block
        }
    
    Should work .. maybe .. perhaps
    Last edited: Jan 9, 2016
  7. davidm1

    davidm1 aMember User & Partner

    Joined:
    May 16, 2006
    Messages:
    4,437
    Right- but I want
    $myStuffSwitch = true;
    to be set by an option in the amember admin GUI.

    david
  8. jenolan

    jenolan aMember Coder

    Joined:
    Nov 3, 2006
    Messages:
    510
    Then you need a plugin like I said at the start
  9. jenolan

    jenolan aMember Coder

    Joined:
    Nov 3, 2006
    Messages:
    510
    In site...
    Code:
    class Am_Form_Setup_Option extends Am_Form_Setup
    {
        function __construct()
        {
            parent::__construct('Option');
            $this->setTitle(___('Options'));
            $this->data['help-id'] = 'Setup/Options';
        }
        function initElements()
        {
            $this->addElement('advcheckbox', 'myoption.switch', null)
            ->setLabel(___('Enable Switch'));
        }
    }
    
    Get value
    Code:
    $di = Am_Di::getInstance(); 
    $val = $di->config->get('myoption.switch', false )
  10. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    David,

    Do you want to control it on form basic (checkbox in signup form edit) or globally (checkbox in configuration)?
    What is part of signup form you want to hide/show? Do you want to skip some bricks?

    Thanks.
  11. davidm1

    davidm1 aMember User & Partner

    Joined:
    May 16, 2006
    Messages:
    4,437
    globally (checkbox in configuration) - in the admin setup or other admin screen.

    I'd like to essentially hide the entire signup form if this is enabled and show another one text.

    EG
    unchecked - > show order form
    checked -> show signup form/waiting list (no order)
  12. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    Here is small mock up for misc plugin that do it, you can extend it according your requirements
    PHP:
    <?php
    class Am_Plugin_HideSignupForm extends Am_Plugin
    {
        protected 
    $_configPrefix 'misc.';

        function 
    _initSetupForm(Am_Form_Setup $form)
        {
            
    $form->addAdvCheckbox('hide')
                ->
    setLabel('Hide Signup Form');
        }

        function 
    onLoadSignupForm(Am_Event $e)
        {
            if (!
    $this->getConfig('hide')) return;

            
    $form $e->getReturn();
            if (
    $form->code == 'OU0DHw7XE') {
                
    $view $this->getDi()->view;
                
    $view->title "Your Title";
                
    $view->content = <<<CUT
    <strong>Your message here</strong>
    CUT;
                
    $view->display('member/layout.phtml');
                throw new 
    Am_Exception_Redirect;
            }
        }
    }
    You need to put this code to file
    amember/application/default/plugins/misc/hide-signup-form.php
    and then enable plugin at aMember CP -> Configuration -> Setup/Configuration -> Plugins (Other Plugins)
  13. jenolan

    jenolan aMember Coder

    Joined:
    Nov 3, 2006
    Messages:
    510
    I took this and made CSaLT -- Coming Soon & Limited Time, it does the following
    • Start/End Date for a sale/campaign
    • Limit total sales and/or sales to a client
    • Optionally totally hide product from all but the CSaLT designated signup form
    • Redirect user to a page (default error message if blank) for
      • Too Early -- Tried before start date
      • Too Late -- Tried after finish date
      • Too Many -- Sold out
      • Too Many User -- limit per client
    I think I have the coding part done, just needs some documentation though. The options make it twiddly but it is set out to be easily understood if you understand the concept.

Share This Page