1

I have created the customer's custom attribute in the registration page to upload the proof of business document as Business Registration File using below code.

module.xml

<?xml version="1.0" encoding="utf-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="MyModules_CustomerUploadFile" setup_version="1.0.0">
    </module>
</config>  

InstallData.php

<?php
namespace MyModules\CustomerUploadFile\Setup;
use Magento\Framework\Module\Setup\Migration;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;

/**
 * @codeCoverageIgnore
 */
class InstallData implements InstallDataInterface
{

    protected $_logger;

    /**
     * Constructor
     * @param \YourNamespace\YourModule\Logger\Logger $logger

    */

    /**
     * Customer setup factory
     *
     * @var \Magento\Customer\Setup\CustomerSetupFactory
     */
    private $customerSetupFactory;
    /**
     * Init
     *
     * @param \Magento\Customer\Setup\CustomerSetupFactory $customerSetupFactory
     */
    public function __construct(\Magento\Customer\Setup\CustomerSetupFactory $customerSetupFactory)
    {
        $this->customerSetupFactory = $customerSetupFactory;
    }
    /**
     * Installs DB schema for a module
     *
     * @param ModuleDataSetupInterface $setup
     * @param ModuleContextInterface $context
     * @return void
     */
    public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
    {
        $installer = $setup;
        $installer->startSetup();

        $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
        $entityTypeId = $customerSetup->getEntityTypeId(\Magento\Customer\Model\Customer::ENTITY);

        $customerSetup->addAttribute(\Magento\Customer\Model\Customer::ENTITY, "business_registration_file",  array(
            "type"     => "varchar",
            "backend"  => "",
            "label"    => "Business Registration Doc.",
            "input"    => "file",
            "source"   => '',
            "visible"  => true,
            "required" => true,
            "default"  => "",
            "frontend" => "",
            "unique"   => false,
            "note"     => "",
            "is_used_in_grid"       => true,
            "is_visible_in_grid"    => true,
            "is_filterable_in_grid" => true,
            "is_searchable_in_grid" => true

        ));
        $regulation = $customerSetup->getEavConfig()->getAttribute(\Magento\Customer\Model\Customer::ENTITY, 'business_registration_file');
        $used_in_forms[]="customer_account_edit";
        $used_in_forms[]="customer_account_create";      
        $used_in_forms[]="adminhtml_customer";

        $regulation->setData("used_in_forms", $used_in_forms)
            ->setData("is_used_for_customer_segment", true)
            ->setData("is_system", 0)
            ->setData("is_user_defined", 1)
            ->setData("is_visible", 1)
            ->setData("sort_order", 100);
        $regulation->save();



        $installer->endSetup();
    }


}
?>

customer_account_create.xml

<?xml version="1.0" encoding="utf-8"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">

<body>
    <referenceContainer name="form.additional.info">
        <block class="Magento\Framework\View\Element\Template" name="my_form_additional_info_customer" template="MyModules_CustomerUploadFile::additionalinfocustomer.phtml"/>
    </referenceContainer>
</body>
</page>

additionalinfocustomer.phtml

<fieldset class="fieldset create account" data-hasrequired="<?php /*@escapeNotVerified */ echo __('* Required Fields') ?>">
 <div class="field upload_file required">
         <label for="business_registration_file"><?php echo $this->__('Business Registration Doc.') ?><span class="required">*</span></label><br />
         <div class="control">
            <input type="file" name="business_registration_file" id="business_registration_file" title="<?php echo $this->__('Business Registration Doc.') ?>" class="required-entry input-file" />
         </div>
     </div>
 </div>
 </fieldset>

Error:

Invalid method Magento\Framework\View\Element\Template::__(Array
(
    [0] => Business Registration Doc.
)
)
#0 [internal function]: Magento\Framework\DataObject->__call('__', Array)
#1 [internal function]: Magento\Framework\View\Element\Template->__('Business Regist...')
#2 /var/www/html/lib/internal/Magento/Framework/View/TemplateEngine/Php.php(82): call_user_func_array(Array, Array)
#3 /var/www/html/app/code/MyModules/CustomerMarketingFields/view/frontend/templates/additionalinfocustomer.phtml(26): Magento\Framework\View\TemplateEngine\Php->__call('__', Array)
#4 /var/www/html/app/code/MyModules/CustomerMarketingFields/view/frontend/templates/additionalinfocustomer.phtml(26): Magento\Framework\View\TemplateEngine\Php->__('Business Regist...')
#5 /var/www/html/lib/internal/Magento/Framework/View/TemplateEngine/Php.php(59): include('/var/www/html/a...')
#6 /var/www/html/lib/internal/Magento/Framework/View/Element/Template.php(255): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\Framework\View\Element\Template), '/var/www/html/a...', Array)
#7 /var/www/html/lib/internal/Magento/Framework/View/Element/Template.php(279): Magento\Framework\View\Element\Template->fetchView('/var/www/html/a...')
#8 /var/www/html/lib/internal/Magento/Framework/View/Element/AbstractBlock.php(657): Magento\Framework\View\Element\Template->_toHtml()
#9 /var/www/html/lib/internal/Magento/Framework/View/Layout.php(542): Magento\Framework\View\Element\AbstractBlock->toHtml()
#10 /var/www/html/lib/internal/Magento/Framework/View/Layout.php(518): Magento\Framework\View\Layout->_renderBlock('my_form_additio...')
#11 /var/www/html/var/generation/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('my_form_additio...')
#12 /var/www/html/lib/internal/Magento/Framework/View/Layout.php(472): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('my_form_additio...')
#13 /var/www/html/var/generation/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('my_form_additio...', true)
#14 /var/www/html/lib/internal/Magento/Framework/View/Layout.php(569): Magento\Framework\View\Layout\Interceptor->renderElement('my_form_additio...')
#15 /var/www/html/lib/internal/Magento/Framework/View/Layout.php(520): Magento\Framework\View\Layout->_renderContainer('form.additional...')
#16 /var/www/html/var/generation/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('form.additional...')
#17 /var/www/html/lib/internal/Magento/Framework/View/Layout.php(472): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('form.additional...')
#18 /var/www/html/var/generation/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('form.additional...', true)
#19 /var/www/html/lib/internal/Magento/Framework/View/Element/AbstractBlock.php(497): Magento\Framework\View\Layout\Interceptor->renderElement('form.additional...', true)
#20 /var/www/html/app/code/Magento/Customer/view/frontend/templates/form/register.phtml(152): Magento\Framework\View\Element\AbstractBlock->getChildHtml('form_additional...')
#21 /var/www/html/lib/internal/Magento/Framework/View/TemplateEngine/Php.php(59): include('/var/www/html/a...')
#22 /var/www/html/lib/internal/Magento/Framework/View/Element/Template.php(255): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\Customer\Block\Form\Register), '/var/www/html/a...', Array)
#23 /var/www/html/lib/internal/Magento/Framework/View/Element/Template.php(279): Magento\Framework\View\Element\Template->fetchView('/var/www/html/a...')
#24 /var/www/html/lib/internal/Magento/Framework/View/Element/AbstractBlock.php(657): Magento\Framework\View\Element\Template->_toHtml()
#25 /var/www/html/lib/internal/Magento/Framework/View/Layout.php(542): Magento\Framework\View\Element\AbstractBlock->toHtml()
#26 /var/www/html/lib/internal/Magento/Framework/View/Layout.php(518): Magento\Framework\View\Layout->_renderBlock('customer_form_r...')
#27 /var/www/html/var/generation/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('customer_form_r...')
#28 /var/www/html/lib/internal/Magento/Framework/View/Layout.php(472): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('customer_form_r...')
#29 /var/www/html/var/generation/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('customer_form_r...', true)
#30 /var/www/html/lib/internal/Magento/Framework/View/Layout.php(569): Magento\Framework\View\Layout\Interceptor->renderElement('customer_form_r...')
#31 /var/www/html/lib/internal/Magento/Framework/View/Layout.php(520): Magento\Framework\View\Layout->_renderContainer('content')
#32 /var/www/html/var/generation/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('content')
#33 /var/www/html/lib/internal/Magento/Framework/View/Layout.php(472): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('content')
#34 /var/www/html/var/generation/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('content', true)
#35 /var/www/html/lib/internal/Magento/Framework/View/Layout.php(569): Magento\Framework\View\Layout\Interceptor->renderElement('content')
#36 /var/www/html/lib/internal/Magento/Framework/View/Layout.php(520): Magento\Framework\View\Layout->_renderContainer('main')
#37 /var/www/html/var/generation/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('main')
#38 /var/www/html/lib/internal/Magento/Framework/View/Layout.php(472): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('main')
#39 /var/www/html/var/generation/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('main', true)
#40 /var/www/html/lib/internal/Magento/Framework/View/Layout.php(569): Magento\Framework\View\Layout\Interceptor->renderElement('main')
#41 /var/www/html/lib/internal/Magento/Framework/View/Layout.php(520): Magento\Framework\View\Layout->_renderContainer('columns')
#42 /var/www/html/var/generation/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('columns')
#43 /var/www/html/lib/internal/Magento/Framework/View/Layout.php(472): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('columns')
#44 /var/www/html/var/generation/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('columns', true)
#45 /var/www/html/lib/internal/Magento/Framework/View/Layout.php(569): Magento\Framework\View\Layout\Interceptor->renderElement('columns')
#46 /var/www/html/lib/internal/Magento/Framework/View/Layout.php(520): Magento\Framework\View\Layout->_renderContainer('main.content')
#47 /var/www/html/var/generation/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('main.content')
#48 /var/www/html/lib/internal/Magento/Framework/View/Layout.php(472): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('main.content')
#49 /var/www/html/var/generation/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('main.content', true)
#50 /var/www/html/lib/internal/Magento/Framework/View/Layout.php(569): Magento\Framework\View\Layout\Interceptor->renderElement('main.content')
#51 /var/www/html/lib/internal/Magento/Framework/View/Layout.php(520): Magento\Framework\View\Layout->_renderContainer('page.wrapper')
#52 /var/www/html/var/generation/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('page.wrapper')
#53 /var/www/html/lib/internal/Magento/Framework/View/Layout.php(472): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('page.wrapper')
#54 /var/www/html/var/generation/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('page.wrapper', true)
#55 /var/www/html/lib/internal/Magento/Framework/View/Layout.php(569): Magento\Framework\View\Layout\Interceptor->renderElement('page.wrapper')
#56 /var/www/html/lib/internal/Magento/Framework/View/Layout.php(520): Magento\Framework\View\Layout->_renderContainer('root')
#57 /var/www/html/var/generation/Magento/Framework/View/Layout/Interceptor.php(206): Magento\Framework\View\Layout->renderNonCachedElement('root')
#58 /var/www/html/lib/internal/Magento/Framework/View/Layout.php(472): Magento\Framework\View\Layout\Interceptor->renderNonCachedElement('root')
#59 /var/www/html/var/generation/Magento/Framework/View/Layout/Interceptor.php(193): Magento\Framework\View\Layout->renderElement('root', true)
#60 /var/www/html/lib/internal/Magento/Framework/View/Layout.php(938): Magento\Framework\View\Layout\Interceptor->renderElement('root')
#61 [internal function]: Magento\Framework\View\Layout->getOutput()
#62 /var/www/html/lib/internal/Magento/Framework/Interception/Interceptor.php(146): call_user_func_array(Array, Array)
#63 /var/www/html/var/generation/Magento/Framework/View/Layout/Interceptor.php(494): Magento\Framework\View\Layout\Interceptor->___callPlugins('getOutput', Array, Array)
#64 /var/www/html/lib/internal/Magento/Framework/View/Result/Page.php(241): Magento\Framework\View\Layout\Interceptor->getOutput()
#65 /var/www/html/lib/internal/Magento/Framework/View/Result/Layout.php(162): Magento\Framework\View\Result\Page->render(Object(Magento\Framework\App\Response\Http\Interceptor))
#66 [internal function]: Magento\Framework\View\Result\Layout->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#67 /var/www/html/lib/internal/Magento/Framework/Interception/Interceptor.php(74): call_user_func_array(Array, Array)
#68 /var/www/html/lib/internal/Magento/Framework/Interception/Chain/Chain.php(70): Magento\Framework\View\Result\Page\Interceptor->___callParent('renderResult', Array)
#69 /var/www/html/lib/internal/Magento/Framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\Framewo...', 'renderResult', Object(Magento\Framework\View\Result\Page\Interceptor), Array, 'result-varnish-...')
#70 /var/www/html/app/code/Magento/PageCache/Model/Controller/Result/VarnishPlugin.php(74): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Response\Http\Interceptor))
#71 [internal function]: Magento\PageCache\Model\Controller\Result\VarnishPlugin->aroundRenderResult(Object(Magento\Framework\View\Result\Page\Interceptor), Object(Closure), Object(Magento\Framework\App\Response\Http\Interceptor))
#72 /var/www/html/lib/internal/Magento/Framework/Interception/Chain/Chain.php(68): call_user_func_array(Array, Array)
#73 /var/www/html/lib/internal/Magento/Framework/Interception/Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\Framewo...', 'renderResult', Object(Magento\Framework\View\Result\Page\Interceptor), Array, 'result-builtin-...')
#74 /var/www/html/app/code/Magento/PageCache/Model/Controller/Result/BuiltinPlugin.php(67): Magento\Framework\View\Result\Page\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Response\Http\Interceptor))
#75 [internal function]: Magento\PageCache\Model\Controller\Result\BuiltinPlugin->aroundRenderResult(Object(Magento\Framework\View\Result\Page\Interceptor), Object(Closure), Object(Magento\Framework\App\Response\Http\Interceptor))
#76 /var/www/html/lib/internal/Magento/Framework/Interception/Interceptor.php(143): call_user_func_array(Array, Array)
#77 /var/www/html/var/generation/Magento/Framework/View/Result/Page/Interceptor.php(130): Magento\Framework\View\Result\Page\Interceptor->___callPlugins('renderResult', Array, Array)
#78 /var/www/html/lib/internal/Magento/Framework/App/Http.php(119): Magento\Framework\View\Result\Page\Interceptor->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#79 /var/www/html/lib/internal/Magento/Framework/App/Bootstrap.php(258): Magento\Framework\App\Http->launch()
#80 /var/www/html/index.php(41): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
#81 {main}
0

I got it by removing $this-> after the echo function in additionalinfocustomer.phtml file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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