I created customer custom attribute with input multiselect like this:

$code = 'multiselect_test';
$insertData = array(
        "type"     => "text",
        "backend"  => "",
        "label"    => 'Multiselect Input',
        "input"    => 'multiselect',
        "source"   => "",
        "visible"  => true,
        "required" => false,
        "default" => "",
        "frontend" => "",
        "unique"     => false,
        "note"       => ""
       $values = array('Briteny','James');
       $insertData['source'] = 'Magento\Eav\Model\Entity\Attribute\Source\Table';
       $insertData['backend'] = 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend';
       $insertData['option']['values'] = $values;

$customerSetup->addAttribute(\Magento\Customer\Model\Customer::ENTITY, $code,  $insertData);
      $attribute   = $customerSetup->getAttribute(\Magento\Customer\Model\Customer::ENTITY, $code);

      $attribute = $customerSetup->getEavConfig()->getAttribute(\Magento\Customer\Model\Customer::ENTITY, $code);
      $attribute->setData("used_in_forms", $used_in_forms)
      ->setData("is_used_for_customer_segment", true)
      ->setData("is_system", 0)
      ->setData("is_user_defined", 1) 
      ->setData("sort_order", $data['sorting_order']);

    try {
    } catch (Exception $e) {

i created a custom input for customer registration form in frontend for that custom attribute like this:

<select multiple name="multiselect_test">
  <option value="0">Britney</option>
  <option value="1">James</option>

when i looked in backend to edit the customer info in account information the custom attribute input value from frontend was not there, i guess it's because the value for this custom attribute is wrong (not 0 or 1), then i try to insert the value from backend and save it, and the input value save properly, when i try to retrieve the value like this:

$cattrValue = $customer->getCustomAttribute('multiselect_test')->getValue();

i got this result :


In conclusion i need to know how to retrieve this multiselect/dropdown custom attribute real value and label information, so i can use it to create custom attribute input for customer registration properly, or use it for other process in backend

  • try with, $customer->getCustomAttribute('multiselect_test')->getLabel(); Commented Jul 6, 2017 at 6:54
  • @RakeshJesadiya i want to retrieve each option from select input label, not the general label
    – simple guy
    Commented Jul 6, 2017 at 6:57

2 Answers 2


you can use eav atrribute interface to retrieve available options for your dropdown/multiselect like this:

public function __construct(
        \Magento\Eav\Api\AttributeRepositoryInterface $eavAttributeRepository
    ) {
        $this->eavAttributeRepository = $eavAttributeRepository; 

public function retrieveOptions($custom_attribute_code){
        $attributes = $this->eavAttributeRepository->get(\Magento\Customer\Model\Customer::ENTITY, $custom_attribute_code);
        $options = $attributes->getSource()->getAllOptions(false);

Use the below code to get and set custom attribute value.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerObj = $objectManager->create('Magento\Customer\Model\Customer')->getCollection();
    foreach ($customerObj as $customerObjdata) {

        $customermodel  = $objectManager->create('Magento\Customer\Model\Customer');
        $customerData = $customermodel->getDataModel();
        $customerData->setCustomAttribute('is_vendor', 0);

        $customerResource = $objectManager->create('\Magento\Customer\Model\ResourceModel\CustomerFactory')->create();
        $customerResource->saveAttribute($customermodel, 'is_vendor');
  • Why not using dependency injection?
    – PY Yick
    Commented Jul 6, 2017 at 8:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.