如何将多个自定义字段插入Whmcs API

时间:2018-09-15 07:59:40

标签: php laravel laravel-5 whmcs

我有一个问题,需要使用laravel将多个产品自定义字段插入whmcs。在下面的代码中,仅传递$ cp值。但是需要传递$ os,$ db和$ cp值。

$order_details = Whmcs::AddOrder([
            'clientid' => $value,
            'paymentmethod' => 'razorpay',
            'pid' => $pid,
            'domain' => $domain,
            'billingcycle' => $billingcycle,
            'domaintype' => $domain_reg,
            'regperiod' => $domain_regperiod,
    'customfields'=>array(base64_encode(serialize($os))),
    'customfields'=>array(base64_encode(serialize($db))),
    'customfields'=>array(base64_encode(serialize($cp)))
        ]);

1 个答案:

答案 0 :(得分:0)

自定义字段以以下形式显示:

<input name="customfield[5]" type="text">
<input name="customfield[11]" type="text">

提交后,发布的var是:

$_POST['customfield'] = array('5' => '', '11' => '' );

因此,当使用AddOrder函数时,代码变为:

//using Laravel $request
$customFields = base64_encode(serialize($request->input('customfield')));
//or using $_POST array
$customFields = base64_encode(serialize($_POST['customfield']));

$order_details = Whmcs::AddOrder([
            'clientid' => $value,
            'paymentmethod' => 'razorpay',
            'pid' => $pid,
            'domain' => $domain,
            'billingcycle' => $billingcycle,
            'domaintype' => $domain_reg,
            'regperiod' => $domain_regperiod,
            'customfields'=> $customFields
        ]);