Jump to content

Addon Module Configuration - Dropdown Loader Function


Recommended Posts

I have some configuration fields in my addon, one of them I would like to be a dropdown of e-mail templates available in WHMCS. But no info on how to add a funcion in the oficial developer pages on how to setup such a field. Regardless I found another page explaining adding such a field for the rpovisioning module and tried to use it. Code below:

// Select e-mail to send on trial start
'tam-s1' => array (
	'FriendlyName' => 'E-mail Template',
	'Type' => 'text',
	'Size' => '25',
	'Loader' => function () {
		$command = 'GetEmailTemplates';
		$postData = array(
			'type' => 'general',
		);
		$templates = localAPI($command, $postData);
		if ($templates['result'] == 'success') {
			echo 'Message sent successfully!';
		} else {
			echo "An Error Occurred: " . $results['result'];
		}
							print_r($templates,true);
		
		// Format the list of values for display
		// array ('value' => 'Display Label'),
		$list = [];
		foreach ($templates as $emailtemplate) {
			$list[$emailtemplate['id']] = ucfirst($emailtemplate['name']);
		}

		return $list;
	},
	'SimpleMode' => true,
),

But nothing really happens on the addon configuration page. The field in question prints out as a standard text field. Should I assume that the Loader only works within other fields and not the addon config fields? Or am I doing something wrong?

 

Thanks in advance.

 

Link to comment
Share on other sites

I corrected the foreach funcion so that now it returns a proper "ID" => "Description" array of the email templates. But it sill stays as a text input field instead of a nice dropdown list.

'tam-s1' => array (
	'FriendlyName' => 'E-mail Template',
	'Type' => 'text',
	'Size' => '25',
	'Loader' => function () {
        $templates = localAPI('GetEmailTemplates', array( 'type' => 'product' ));
    
        // Format the list of values for display
        // array ('ID' => 'Display Label'),
        foreach ( $templates['emailtemplates']['emailtemplate'] as $a ) {
            $list[$a['id']] = $a['name'];
        }
        
        return($list);
	},
	'SimpleMode' => true,
),

 

Link to comment
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
Reply to this topic...

×   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.

  • 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