cancel
Showing results for 
Search instead for 
Did you mean: 

File Upload Customer Attribute in registration form

File Upload Customer Attribute in registration form

Hi,


Getting issue while creating customer attribute file upload field in customer registration form
Tried the following procedure:
In setup/InstallData.php

<?php

namespace Vendor\CustomerAttribute\Setup;

use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Eav\Model\Config;
use Magento\Customer\Model\Customer;

class InstallData implements InstallDataInterface
{
	private $eavSetupFactory;

	public function __construct(EavSetupFactory $eavSetupFactory, Config $eavConfig)
	{
		$this->eavSetupFactory = $eavSetupFactory;
		$this->eavConfig       = $eavConfig;
	}

	public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
	{
		$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
		$eavSetup->addAttribute(
			\Magento\Customer\Model\Customer::ENTITY,
			'licence_proof',
			[
				'type'         => 'varchar',
				'label'        => 'File Upload',
				'input'        => 'image',
				'required'     => true,
				'visible'      => true,
				'user_defined' => true,
				'position'     => 5,
				'system'       => 0,
			]
		);
		$sampleAttribute = $this->eavConfig->getAttribute(Customer::ENTITY, 'file_upload');

		// more used_in_forms ['adminhtml_checkout','adminhtml_customer','adminhtml_customer_address','customer_account_edit','customer_address_edit','customer_register_address']
		$sampleAttribute->setData(
			'used_in_forms',
			['adminhtml_customer', 'customer_account_create', 'customer_account_edit']

		);
		$sampleAttribute->save();
	}
}

Also added the following input in customer register.phtml

<input type="file" name="file_upload" id="file_upload" title="title" class="required-entry input-text file_upload" />

Then after submitting the form we are getting error: file_upload is a required value even after filling all the fields.

Please suggest a solution.

1 REPLY 1

Re: File Upload Customer Attribute in registration form

I'm Also having same issue file is not being uploaded, and one more thing how can I show this file in user profile edit form?