【问题标题】:How to insert multiple custom fields to whmcs API如何将多个自定义字段插入到 whmcs API
【发布时间】:2018-09-15 07:59:40
【问题描述】:

我在使用 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)))
        ]);

【问题讨论】:

    标签: php laravel laravel-5 whmcs


    【解决方案1】:

    自定义字段以如下形式呈现:

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

    提交后,post vars 为:

    $_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
            ]);
    

    【讨论】:

    • 始终清理来自 $_POST $_REQUEST 或 $_GET 的数据
    • 是的,我想,只是想提一下它总是让人们养成清理数据的习惯......即使你只是直接检查=== 总是很好,仍然可以清理,你可能会稍后更改代码并忘记这样做:)
    猜你喜欢
    • 1970-01-01
    • 2013-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多