Jump to content

ClientAdd and ClientEdit hook access to custom field?


Recommended Posts

I have a working ClientAdd hook and would like to extend its feature to access the custom text field named "website". Does anyone have an example of how to grab the custom fields value? Also, I noticed the Docs mentions "customFields" variable for ClientAdd, but I don't see that variable in ClientEdit docs. Is it possible to access customFields from the ClientEdit hook?

Link to comment
Share on other sites

I dug a little further and figured out how to access the customFields via

$vars['customfields']['1'];

, but it seems that I cannot access the customeFields inside of the clientEdit hook. I placed a

die(json_encode($vars));

at the top in the clientEdit hook to output the array in JSON format so its easily readable. I then noticed the customfield could be accessible from within "olddata", but that defeats the purpose of getting the 'updated' field value. Will I need to use the Capsule API access the value via mysql?

Link to comment
Share on other sites

Using this example, I can access the customfield 'website' field value

 

code:

<?php

if (!defined("WHMCS"))

die("This file cannot be accessed directly");

 

use WHMCS\Database\Capsule;

 

add_hook('ClientEdit', 1, function($vars) {

//die(json_encode($vars));

$userid = $vars['userid'];

 

foreach (Capsule::table('tblcustomfieldsvalues')->where('fieldid','1')->where('relid', $userid)->get() as $client) {

//Do stuffs

}

 

});

 

So, my question still remains.... Do I need to use the Capsule API to access the customfields value from the clientEdit hook? Or am I overlooking something?

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