Jump to content

Question

i want to loop through all these checkboxes and generate them dynamically according to their roles and to concatenate role id dynamically  with their friendly names  instead of writing them manually , is there any way to do this ? 

 

function leave_module_config()
{
    return [
        'fields' => [
            'Checkbox Field Name' => [
                'FriendlyName' => 'role1',
                'Type' => 'yesno',
                'Description' => 'Tick to enable',
                
                'FriendlyName' => 'role2',
                'Type' => 'yesno',
                'Description' => 'Tick to enable',
                
                'FriendlyName' => 'role3',
                'Type' => 'yesno',
                'Description' => 'Tick to enable',
                
                'FriendlyName' => 'role4',
                'Type' => 'yesno',
                'Description' => 'Tick to enable',
            ],
        ]
    ];
}

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

 To loop through the roles and generate the checkboxes dynamically, you can use a PHP foreach loop to iterate over an array of roles and create the checkboxes inside the loop. Here is an example of how you could do this:

function leave_module_config()
{
    $roles = ['role1', 'role2', 'role3', 'role4'];

    $fields = [
        'Checkbox Field Name' => []
    ];

    foreach ($roles as $role) {
        $fields['Checkbox Field Name'][] = [
            'FriendlyName' => $role,
            'Type' => 'yesno',
            'Description' => 'Tick to enable',
        ];
    }

    return [
        'fields' => $fields
    ];
}


This code will create a checkbox for each role in the $roles array. The FriendlyName for each checkbox will be set to the corresponding role name, and the Type and Description will be set to the same values for all checkboxes.

You can modify this code to suit your specific needs, such as by adding additional fields or by generating the role names and IDs dynamically from a database or other source.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Similar Content

    • By Dika John
      Hello there,
      Is it possible for http request using PUT method in addon module ? If possible,  any ideas how to use it ?
      Please help me
       
      Thank you
    • By yhonaqc
      Free Elegant AltiplanoHost WHMCS Email Template
      With great humility, gratitude and at the request of many, we have released version 2.2 of our email template Elegant AltiplanoHost WHMCS Email Template
         that now comes in the form of an addon totally free and easy to install.
      You do not need to have knowledge of html and/or CSS, just install and activate our module,
      Our module is thanks to our staff at altilanohost.com who are enthusiastic about development.
      You can choose from 4 styles
      Intuitive dashboard
      NEWS:
      Multilanguage (NEW V2.2)
       





    • By Waqas Saeed
      Recently we have encountered a issue related to our Billing, the ResellerClub has decided to add the individual charges/fee for each account in Linux Reseller Hosting, therefore, we have many cPanel account and we weren't charging our client individually for cP license fee. so could you please help us understand the procedure so that we can do the following without disturbing their basic package hosting.
      - Forcefully add (cPanel Fee Add-on) in the next invoice , and also compulsory to all Shared products only (hosting) based on monthly, yearly, or biannually billing.
    • By Rowan S
      Hello,
      Is anybody able to assist with a issue I’m having with my WHMCS licence module. The WHMCS licence module is a module which automatically registers/creates WHMCS licences. 
      The idea is that you could utilise the daily cron hook point to run some additional code to check every WHMCS licence addon’s check the next due date and cancel the license if it’s in the past. 
      I don’t believe that this would be too difficult to code but I am not familiar with this. It would be greatly appreciated if somebody could code this for me. 
      Thanks! 
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated