Change Yes/No element based on user access level

Discussion in 'Professional Support' started by keianrad, Sep 12, 2017.

Thread Status:
Not open for further replies.
  1. keianrad

    keianrad Member

    Level: Community
    There is a Yes/No element in a form in a hidden group. I need to change the value based on the user access level of user who is submitting the form.

    I need to be "No" for registered level and be "Yes" for Special level.

    Is it possible?
    Thank you for your help.
     
  2. troester

    troester Well-Known Member Staff Member

    Level: Standard
    Change (=set) on submit?
    You could use a php validation with 'replace' or a php plugin

    Gesendet von meinem GT-I9300 mit Tapatalk
     
  3. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Professional
    I'd go for the PHP plugin, although the validation would work.

    A PHP form plugin, running onBeforeProcess ...

    Code (Text):

    $myLevels = JFactory::getUser()->getAuthorisedViewLevels();
    if (in_array(3, $myLevels)) {
       $formModel->updateFormData('yourtable___yesno', '1', true);
    }
    else {
       $formModel->updateFormData('yourtable___yesno', '0', true);
    }
     
    Change yourtable___yesno to your full element name.

    NOTE - this sets to Yes if Special, and No if not Special. You said to set to Yes if Special and No if Registered ... but that doesn't handle cases where the user is neither, or both.

    So I'm not sure what you want to do if they are neither or both, but I'm assuming your logic should really be as I've written it. Set to Yes if Special, otherwise No.

    -- hugh
     
    keianrad likes this.
Thread Status:
Not open for further replies.

Share This Page