I have created a custom attribute for customer using below code.
setup/installData.php
$customerSetup->addAttribute(\Magento\Customer\Model\Customer::ENTITY, 'samsung', [
'type' => 'varchar',
'label' => 'Samsung ',
'input' => 'boolean',
'source' => '',
'required' => false,
'visible' => true,
'position' => 166,
'system' => false,
'backend' => ''
]);
$attribute = $customerSetup->getEavConfig()->getAttribute('customer', 'samsung')
->addData(['used_in_forms' => [
'adminhtml_customer',
'adminhtml_checkout',
'customer_account_create',
'customer_account_edit'
]]);
$attribute->save();
I am using below front-end code but data is not stored in the database:
<div class="field apple">
<div class="control">
<input type="checkbox" name="acs" id="apple" value="Apple" class="checkbox">apple
</div>
</div>
<div class="field samsung">
<div class="control">
<input type="checkbox" name="acs" id="samsung" value="Samsung" class="checkbox">Samsung
</div>
</div>
<div class="field sony">
<div class="control">
<input type="checkbox" name="acs" id="sony" value="Sony" class="checkbox">Sony
</div>
</div>
<div class="field dell">
<div class="control">
<input type="checkbox" name="acs" id="dell" value="Dell" class="checkbox">Dell
</div>
</div>
<input type="button" onclick='selectAll()' value="Select All"/>
<input type="button" onclick='UnSelectAll()' value="Unselect All"/>
<script type="text/javascript">
function selectAll(){
var items=document.getElementsByName('acs');
for(var i=0; i<items.length; i++){
if(items[i].type=='checkbox')
items[i].checked=true;
}
}
function UnSelectAll(){
var items=document.getElementsByName('acs');
for(var i=0; i<items.length; i++){
if(items[i].type=='checkbox')
items[i].checked=false;
}
}
</script>