cyberpods Posted September 30, 2016 Share Posted September 30, 2016 Hi all, I'm trying to add a custom field to a clients account when their account is created and cant't seem to get it working. This code works when I save any field on a clients account that's already created. add_hook( 'CustomFieldSave', 1, function($vars) { //Check that the fieldid is one you wish to override if ($vars['fieldid'] == 1 && strlen($vars['value']) == '0') { return array('value' => "MyCustomField"); } return array(); } ); But this does not work. add_hook( 'ClientAdd', 1, function($vars) { //Check that the fieldid is one you wish to override if ($vars['fieldid'] == 1 && strlen($vars['value']) == '0') { return array('value' => "MyCustomField"); } return array(); } ); What am I doing wrong? 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted September 30, 2016 Share Posted September 30, 2016 you need to treat each ActionHook Points differently, what is working on "CustomFieldSave" will not work in "ClientAdd", read: http://docs.whmcs.com/Hooks:ClientAdd in ClientAdd, custom fields passed as array $vars['customfields'], this what you need to validate, and if you want to make changes to it, you would need to add the updated value directly in database 0 Quote Link to comment Share on other sites More sharing options...
cyberpods Posted October 1, 2016 Author Share Posted October 1, 2016 Ok, I figured it out. I decided to use the internal API to make the changes. Here is the code I'm using if it can help anyone else. add_hook( 'ClientAdd', 1, function($vars) { $userid = $vars['userid']; $command = "updateclient"; $adminuser = "adminuser"; $values["clientid"] = $userid; $values["customfields"] = base64_encode(serialize(array("1"=>"CustomValueStringToSave"))); $results = localAPI($command,$values,$adminuser); return array(); } ); 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.