How to add custom field in signup(CREATE ACCOUNT) page in frontend. I have tried some example module but i am getting this
Error "1 exception(s): Exception #0 (Magento\Framework\Exception\LocalizedException): Please upgrade your database: Run "bin/magento setup:upgrade" from the Magento root directory. The following modules are outdated: Multi_Beta data: current version - none, required version - 0.1.1"
InstallData.php
<?php
namespace Multi\Beta\Setup;
use Magento\Framework\Module\Setup\Migration;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
class InstallData implements InstallDataInterface
{
/**
* 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->removeAttribute(\Magento\Customer\Model\Customer::ENTITY, "my_attribute");
$customerSetup->addAttribute(\Magento\Customer\Model\Customer::ENTITY, "my_attribute", array(
"type" => "varchar",
"backend" => "",
"label" => "My Attribute",
"input" => "text",
"source" => "",
"visible" => true,
"required" => true,
"default" => "",
"frontend" => "",
"unique" => false,
"note" => ""
));
$my_attribute = $customerSetup->getAttribute(\Magento\Customer\Model\Customer::ENTITY, "my_attribute");
$my_attribute = $customerSetup->getEavConfig()->getAttribute(\Magento\Customer\Model\Customer::ENTITY, ' my_attribute');
$used_in_forms[]="adminhtml_customer";
$used_in_forms[]="checkout_register";
$used_in_forms[]="customer_account_create";
$used_in_forms[]="customer_account_edit";
$used_in_forms[]="adminhtml_checkout";
$my_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("is_visible", 1)
->setData("sort_order", 100);
$my_attribute->save();
$installer->endSetup();
}
}
customer_account_create.xml
<?xml version="1.0"?>
<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="Multi_Beta::additionalinfocustomer.phtml"/>
</referenceContainer>
</body>
</page>
additionalinfocustomer.phtml
<fieldset class="fieldset create account" data-hasrequired="<?php /* @escapeNotVerified */ echo __('* Required Fields') ?>">
<legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Additional Information') ?></span></legend><br></p>
<p> <div class="field my_attribute required">
<label for="my_attribute" class="label"><span><?php /* @escapeNotVerified */ echo __('My Attribute') ?></span></label>
<div class="control">
<input type="text" name="my_attribute" id="my_attribute" title="<?php /* @escapeNotVerified */ echo __('My Attribute') ?>" class="input-text" data-validate="{required:true}" autocomplete="off">
</div>
</div>
</div>
</fieldset>
module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="Multi_Beta" setup_version="0.1.1">
<sequence>
<module name="Magento_Directory" />
<module name="Magento_Config" />
</sequence>
</module>
</config>