Jump to content
  • 0
Sign in to follow this  

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.

Sign in to follow this  

  • Similar Content

    • By C1212
      I am new to WHMCS addon module development, forgive me if I am asking this wrongly.

      I am working on an addon module that works with support tickets.
      I would like to add a checkbox to the submit ticket form in the client area. When checked, would be treated differently in the module hook.
      But that checkbox should not show on the client area page if the module isn't enabled/activated.
      The hook point 'ClientAreaPageSubmitTicket'  allows returning  key/value pairs to be made available as additional Smarty template parameters. Which can then be used in the theme template file. I would like not to edit the template file so that the addon module can easily be used on different themes.

      What is the best way to update the content of template from addon modules without editing the template files?
    • 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.
  • 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