Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 752 Vote(s) - 3.43 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Whmcs Client Custom Field Value

#1
Try my luck here after 1 week of no sucessfull help from WHMCS forum, and support only refering to Docs and Forum.

I wish to get value from fields from Client Custom fields, where I know the fieldname

Per documentation and forum post this should in theory work, but it doesnt, nothing is returned. Any idea?

$clientFields = Client::find($clientID)->customFieldValues ;
foreach($clientFields AS $field)
{

if (isset($field->customField->fieldName)

and $field->customField->fieldName == 'NoridCID')

{
$xml .= $field->customField->value; // Add ID to XML
}

else
{
return array("error" => "Some Error Message");

}
}


Reply

#2
This should really be very easy. I'm going to show you the different ways of doing this depending on what you want you want to retrieve and the information you have at hand. Of course I know what you know is the `fieldname`, though I would recommend getting into your `tblcustomfields` table of your WHMCS installation and retrieve the `id` value for that custom field. Now let's get down to the code:

**First: Include the following code:**
````
require("init.php");
use WHMCS\Database\Capsule;
````

**Second: Declare the known variable:**

I am assuming you already have the values you know. So I'm just going to use my pseudo values here:
````
$clientID = 12;
$customFieldID = 1;
$customFieldName = 'Where did you hear about us?';
````
**Third: Add the code to retrieve the data**

I am going to use four codes. Choose what best suites your need.

**A: Get Custom Field value for 1 client. You have client ID and Custom Field Name**
````
$customFieldValue1 = Capsule::table('tblcustomfields')
->join('tblcustomfieldsvalues','tblcustomfieldsvalues.fieldid','=','tblcustomfields.id')
->where('tblcustomfieldsvalues.relid','=',$clientID)
->where('tblcustomfields.fieldname','=',$customFieldName)
->value('tblcustomfieldsvalues.value');

//Use the retrieved vaue e.g echo
echo $customFieldValue1."<br/>";
````

**B: Get Custom Field value for 1 client. You have client ID and Custom Field ID**

````
$customFieldValue2 = Capsule::table('tblcustomfieldsvalues')
->where('relid',$clientID)
->where('fieldid',$customFieldID)
->value('value');

//Use the retrieved vaue e.g echo
echo $customFieldValue2."<br/>";
````

**C: Get Custom Field value for ALL clients. You have client ID and Custom Field Name**

````
$customFieldValues1 = Capsule::table('tblcustomfields')
->join('tblcustomfieldsvalues','tblcustomfieldsvalues.fieldid','=','tblcustomfields.id')
->select('tblcustomfieldsvalues.value as value','tblcustomfieldsvalues.relid as client')
->where('tblcustomfields.fieldname','=',$customFieldName)
->get();

//use retrieved values
foreach($customFieldValues1 as $customField){
$clientId = $customField->client;
$customFieldValue = $customField->value;

echo $clientId." : ".$customFieldValue."<br/>";
}
````

**C: Get Custom Field values for ALL clients. You have client ID and Custom Field ID**

````
$customFieldValues2 = Capsule::table('tblcustomfieldsvalues')
->select('relid as client','value')
->where('fieldid',$customFieldID)
->get();

//use retrieved values
foreach($customFieldValues2 as $customField){
$clientId = $customField->client;
$customFieldValue = $customField->value;

echo $clientId." : ".$customFieldValue."<br/>";
}
````

Please let me know if this answers your question.

For more info on how to write queries with laravel which WHMCS currently uses for interacting with databases, you may visit <https://laravel.com/docs/5.2/queries>
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through