Hello, I'm new in Magento.
I have searched but I haven't found the solution.
I need to add some custom fields to my register form. I'm using a Purpletree marketplace.
Thank you!
Hello @carlos_ortiz2,
If you want to add new field, in customer account, you need to override the register.phtml in your custom theme.
Create custom theme, then create register.phtml in following path
app/design/frontend/vendor/theme/Magento_Customer/templates/form/register.phtml
Then, copy codes, from module-customer/view/frontend/templates/form/register.phtml and paste to above created file.
Then, add your custom field:
<div class="field required"> <label for="custom_field" class="label"><span><?= __('CustomField') ?></span></label> <div class="control"> <input type="text" name="custom_field" id="custom_field" value="<?= $block->escapeHtml($block->getFormData()->getCustomField()) ?>" title="<?= __('CustomField') ?>" class="input-text" data-validate="{required:true, 'validate-phoneStrict':true}"> </div> </div>
Before you do that, you need to create customer attribute for your custom_field to store the database.
Create the Customer Attribute:
You need to create a custom module to do that, after create Custom Module
Create InstallData.php in following path Vendor\Module\Setup
InstallData.php
In this below code I have added custon_field attribute.
<?php /** * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ namespace Vendor\Module\Setup; use Magento\Customer\Setup\CustomerSetupFactory; use Magento\Customer\Model\Customer; use Magento\Eav\Model\Entity\Attribute\Set as AttributeSet; use Magento\Eav\Model\Entity\Attribute\SetFactory as AttributeSetFactory; use Magento\Framework\Setup\InstallDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; /** * Install data * @codeCoverageIgnore */ class InstallData implements InstallDataInterface { /** * CustomerSetupFactory * @var CustomerSetupFactory */ protected $customerSetupFactory; /** * $attributeSetFactory * @var AttributeSetFactory */ private $attributeSetFactory; /** * initiate object * @param CustomerSetupFactory $customerSetupFactory * @param AttributeSetFactory $attributeSetFactory */ public function __construct( CustomerSetupFactory $customerSetupFactory, AttributeSetFactory $attributeSetFactory ) { $this->customerSetupFactory = $customerSetupFactory; $this->attributeSetFactory = $attributeSetFactory; } /** * install data method * @param ModuleDataSetupInterface $setup * @param ModuleContextInterface $context */ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { /** @var CustomerSetup $customerSetup */ $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]); $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer'); $attributeSetId = $customerEntity->getDefaultAttributeSetId(); /** @var $attributeSet AttributeSet */ $attributeSet = $this->attributeSetFactory->create(); $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId); /** * customer registration form default field mobile number */ $customerSetup->addAttribute(Customer::ENTITY, 'custom_field', [ 'type' => 'varchar', 'label' => 'Custom Field', 'input' => 'text', 'required' => true, 'visible' => true, 'user_defined' => true, 'sort_order' => 1000, 'position' => 1000, 'system' => 0, ]); //add attribute to attribute set $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'mobile_number') ->addData([ 'attribute_set_id' => $attributeSetId, 'attribute_group_id' => $attributeGroupId, 'used_in_forms' => ['adminhtml_customer', 'customer_account_create'], ]); $attribute->save(); } }
After that run below command in Magento root directory
php bin/magento setup:upgrade php bin/magento cache:clean
You will see your custom filed in registration form.
Let me know if you have issue.
--
If my answer is useful, please Accept as Solution & give Kudos
Hello @carlos_ortiz2
Please follow below link to add custom field:
Thank you for your response, but I don't know where I have to put the file .phtml
I'm working with a Purpletree marketplace and I have seen that I have to override a file called beseller.phtml of this Purpletree marketplace.
I don't know if I have to create a module that override this module or if I have to add this file to my theme like you tell me in the solution.
Thank you again.
Hello @carlos_ortiz2
create register.phtml in following path (in your theme)
app/design/frontend/vendor/theme/Magento_Customer/templates/form/register.phtml
Then, copy codes, from module-customer/view/frontend/templates/form/register.phtml and paste to above created file.
Then follow other steps from a shared link. Thanks
Ok, I have followed this steps, I see the news fields in the form, but I don't see this information saved.
When I open admin panel and I go to 'all customer' I supose that this information should be there.
Thank you, Carlos.
Hello, I have seen that in table setup_module there is my new module and in table eav_attribute my new attributte.
However, I don't see this information in (admin panel -> "All customer" -> Edit). Magento doesn't update this infomartion automatically?
Besides, I can't see this information in customer panel in order to edit this information.
Thank you again, Carlos.