ARTICLE

Custom Customer Registration Fields on Magento 2 and Hyva: EAV Attributes, Frontend Form Rendering, and Admin Grid Display

person filling out a form on a laptop screen in a bright minimalist office with white desk and plants

Adding custom fields to the Magento 2 customer registration form requires creating an EAV attribute through a data patch, binding it to the registration and admin forms, rendering the field in the frontend template, and saving the submitted value through an observer or plugin.

How Customer Attributes Work in Magento 2

Adobe Commerce stores customer data using the Entity-Attribute-Value (EAV) model. Instead of adding columns to a flat table for every new field, EAV stores each attribute as a row in customer_entity_varchar, customer_entity_int, or customer_entity_text depending on the data type. This lets you add unlimited custom fields without modifying the database schema directly.

Each customer attribute has metadata that controls where it appears:

Property What It Controls
used_in_forms Which forms display the attribute (admin, registration, account edit, checkout)
is_used_in_grid Whether the attribute is available in the admin customer grid
is_visible_in_grid Whether the attribute column shows by default
is_filterable_in_grid Whether the grid supports filtering by this attribute
is_searchable_in_grid Whether the admin search includes this attribute
required Whether the field must be filled in before form submission
user_defined Whether this is a custom (non-system) attribute

The used_in_forms array is the critical piece. Without the right form codes, your attribute exists in the database but never shows up anywhere. The form codes you will use most often are:

  • adminhtml_customer for the admin customer edit page
  • customer_account_create for the storefront registration form
  • customer_account_edit for the My Account edit page
  • adminhtml_checkout for admin-side order creation

Creating the Attribute with a Data Patch

Modern Magento 2 (2.3 and later) uses data patches instead of InstallData scripts. Create a class in Setup/Patch/Data/ that implements DataPatchInterface:

The data patch does three things:

  1. Calls addAttribute on the CustomerSetup object to create the EAV attribute with its type, label, input type, and grid visibility flags.
  2. Calls addAttributeToSet to assign the attribute to the default attribute set and group.
  3. Loads the attribute through getEavConfig()->getAttribute(), sets the used_in_forms array, and saves through the attribute resource model.

A typical attribute definition for a “Company Name” field looks like this in the addAttribute call:

Entity: customer
Code: company_name
Options:
  type: varchar
  label: Company Name
  input: text
  required: false
  visible: true
  user_defined: true
  position: 120
  system: 0
  is_used_in_grid: 1
  is_visible_in_grid: 1
  is_filterable_in_grid: 1
  is_searchable_in_grid: 1

The used_in_forms call after attribute creation binds it to the registration form, the account edit form, and the admin:

used_in_forms: [
  adminhtml_customer,
  customer_account_create,
  customer_account_edit
]

After writing the patch, run bin/magento setup:upgrade to execute it. The attribute now exists in the EAV tables, but the registration form does not display it yet. That requires a layout and template override.

Rendering the Field on the Registration Form

The storefront registration form has a built-in container called form.additional.info specifically designed for custom fields. You add your field by creating a layout XML file that injects a block into this container.

Layout file at view/frontend/layout/customer_account_create.xml:

<page layout="1column">
  <body>
    <referenceContainer name="form.additional.info">
      <block class="Magento\Framework\View\Element\Template"
             name="company_name_field"
             template="Vendor_Module::registration/company_name.phtml"/>
    </referenceContainer>
  </body>
</page>

Template file at view/frontend/templates/registration/company_name.phtml:

<div class="field company-name">
    <label class="label" for="company_name">
        <span><?= $block->escapeHtml(__('Company Name')) ?></span>
    </label>
    <div class="control">
        <input type="text"
               name="company_name"
               id="company_name"
               value=""
               title="<?= $block->escapeHtmlAttr(__('Company Name')) ?>"
               class="input-text">
    </div>
</div>

This renders on Luma. For the account edit form, you create a similar layout override for customer_account_edit.xml using the form.additional.info container in that layout as well.

Saving the Field Value on Registration

Rendering the input is not enough. When the customer submits the registration form, Magento’s default controller does not automatically save custom fields. You need a plugin or an observer to capture the posted value and persist it.

The cleaner approach is an afterPlugin on \Magento\Customer\Api\AccountManagementInterface::createAccount. This runs after the customer object is created and saved, giving you a customer ID to work with:

The plugin reads company_name from the HTTP request, loads the newly created customer, sets the attribute value through setCustomAttribute, and saves using the CustomerRepositoryInterface. This pattern works for any number of custom fields.

The alternative is an observer on the customer_register_success event, which fires after successful registration. The observer approach works the same way but uses Magento’s event system instead of the plugin interceptor chain. Either method is valid. The plugin approach is more explicit about what it hooks into, which makes it easier to debug when multiple customization points interact.

Rendering on a Hyva Frontend

On Hyva, the registration form uses Alpine.js instead of Knockout.js, and the templates are PHP with Alpine directives rather than .html Knockout templates. The form.additional.info container works the same way in the Hyva layout, but your template needs to follow Hyva’s patterns.

The key differences between Luma and Hyva registration field templates:

Aspect Luma Hyva
JS framework jQuery + jQuery Validate Alpine.js
Validation data-validate attribute x-on:blur + Alpine state or HTML5 required
Form submission Standard form POST Standard form POST (same)
CSS classes field, control, input-text Hyva utility classes (Tailwind)
Template engine .phtml with $block .phtml with $block (same)

For a Hyva-compatible template, use Tailwind classes and Alpine.js validation instead of jQuery Validate:

<div class="mb-4" x-data="{ value: '' }">
    <label for="company_name" class="block text-sm font-medium mb-1">
        <?= $block->escapeHtml(__('Company Name')) ?>
    </label>
    <input type="text"
           name="company_name"
           id="company_name"
           x-model="value"
           class="w-full border rounded px-3 py-2 focus:ring-2">
</div>

If you need client-side validation (required field, pattern matching), wrap the input in an Alpine component that tracks validation state and shows error messages on blur. The form submission itself is a standard POST, so your backend plugin handles saving identically regardless of whether the frontend is Luma or Hyva.

For more complex field types (dropdowns populated from EAV source models, date pickers, file uploads), consider a third-party extension like Amasty Customer Attributes or Webkul Custom Registration Fields, both of which ship Hyva compatibility modules. Building these from scratch requires significant template and GraphQL resolver work that an extension handles out of the box.

Displaying in the Admin Customer Grid

The four grid flags set during attribute creation (is_used_in_grid, is_visible_in_grid, is_filterable_in_grid, is_searchable_in_grid) control admin grid behavior. When all four are set to 1, the attribute column appears in the customer grid by default and supports filtering and searching.

If you set is_used_in_grid to 1 but is_visible_in_grid to 0, the column is available but hidden. Admin users can add it through the grid’s Columns button in the toolbar. This is useful for attributes that only some admin users need to see.

The grid uses the customer_listing UI component, which reads attribute metadata from the EAV configuration. You do not need to modify the UI component XML or add column definitions manually. The grid picks up EAV attributes with grid flags automatically, as long as the attribute has been added to the default attribute set.

If your attribute does not appear in the grid after running setup:upgrade, check these common causes:

  1. The attribute is not assigned to the default customer attribute set. The addAttributeToSet call in your data patch must reference CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER.
  2. The is_used_in_grid flag is missing or set to 0.
  3. The index needs rebuilding. Run bin/magento indexer:reindex customer_grid to refresh the flat grid table.

Showing Custom Fields on the Admin Customer Edit Page

The admin customer edit form is controlled by the customer_form UI component. When you include adminhtml_customer in the used_in_forms array, the attribute appears automatically in the Account Information section of the customer edit page in the admin panel.

If you need the field in a custom section (not Account Information), you create a UI component XML file that adds a new fieldset and assigns your attribute to it. This involves modifying the customer_form.xml layout and adding a field definition with the correct dataScope pointing to your attribute code.

For REST API exposure, custom customer attributes are automatically available through the GET /V1/customers/:id endpoint as part of the custom_attributes array. No additional configuration is needed. The GraphQL layer also exposes custom attributes through the Customer type’s custom_attributes field.

Common Pitfalls and How to Avoid Them

Attribute not saving on registration. The most common mistake is creating the EAV attribute and the template but forgetting the plugin or observer that saves the posted value. The registration controller does not auto-save custom fields. Without the save logic, the input renders and the customer submits the form, but the value is silently discarded.

“Required” validation not working. If you set required: true on the EAV attribute but do not add frontend validation in your template, the backend throws a validation error after form submission instead of showing an inline error message. Add required as an HTML attribute and implement client-side validation in your template.

Attribute appears on registration but not on account edit. You forgot to include customer_account_edit in the used_in_forms array. Each form is independent. Including customer_account_create does not automatically include customer_account_edit.

Grid column shows but values are empty. The customer_grid flat table needs reindexing after you create the attribute. Run bin/magento indexer:reindex customer_grid. Existing customers created before the attribute existed will show blank values until their records are re-saved.

Data patch does not run on upgrade. Make sure your patch class has a unique name and that getDependencies() and getAliases() return the correct values. Magento tracks which patches have run in the patch_list table. If your patch name collides with a previously executed patch, it will be skipped.

When to Use an Extension Instead

Building custom registration fields from scratch is straightforward for simple text fields. It becomes significantly more work when you need:

  • File upload fields (profile photos, business licenses)
  • Dropdown fields populated by EAV source models
  • Conditional field visibility (show field B only when field A has a specific value)
  • Multi-step registration forms
  • Field-level access control (some fields visible only to certain customer groups)
  • Checkout integration where custom attributes appear during order placement

Extensions like Amasty Customer Attributes, Webkul Custom Registration Fields, and FME Additional Customer Attributes handle these cases with admin-configurable field definitions, so you can add fields without writing PHP. Both Amasty and Webkul publish Hyva compatibility modules that render the fields using Alpine.js components.

For Shopify or Shopware stores considering a move to Adobe Commerce, custom registration fields are one area where Magento’s EAV system provides more flexibility than either platform’s native customer model, particularly for B2B scenarios where company-specific fields (tax ID, reseller certificate number, credit limit) are part of the onboarding flow.

If your team needs help implementing custom registration fields, adding them to Hyva’s frontend, or integrating them with your ERP through extension attributes, Bemeir’s Adobe Commerce team has built customer attribute workflows for merchants with everything from simple B2C loyalty fields to complex B2B company registration portals. As a Hyva partner and Adobe Commerce specialist, we handle both the backend EAV setup and the frontend rendering on BigCommerce migration projects and greenfield builds.

FAQ

Can I add a dropdown field to the registration form without an extension?

Yes, but it requires more work than a text field. You set the attribute’s input type to select and create a source model class that returns the option array. Your template then renders a <select> element populated by the source model. On Hyva, the template uses Alpine.js for any dynamic behavior like dependent dropdowns. For a single static dropdown, the EAV source model approach works without an extension.

Do custom registration fields work with Magento’s REST and GraphQL APIs?

Yes. Custom customer attributes appear automatically in the REST API’s custom_attributes array when you retrieve a customer. For GraphQL, the Customer type includes a custom_attributes field. You do not need to write additional API code for basic attribute access. If you need mutation support (creating or updating a customer with custom attributes through GraphQL), you may need a custom resolver depending on your Magento version.

How do I make a custom field required only for B2B customers?

You cannot set conditional requirement rules through the EAV attribute definition alone. The simplest approach is to make the attribute optional in EAV and enforce the requirement through a plugin on the registration save action. The plugin checks the customer group or the registration form type and throws a validation exception if the required field is empty for B2B customers. On the frontend, use JavaScript to toggle the required attribute based on a form selector (like a “Register as Business” checkbox).

Will custom registration fields survive a Magento upgrade?

Yes. EAV attributes created through data patches persist across upgrades because they are stored in the database, not in code that gets overwritten. Your data patch runs once and the attribute stays. The template overrides and plugin code are in your custom module, which is also upgrade-safe as long as you do not modify core files. The only risk is if Adobe changes the form.additional.info container name or the registration controller signature, which has not happened across major Magento 2 releases.

Can I reuse the same custom fields on the checkout page?

Not directly. The checkout uses a different UI component system (Knockout.js on Luma, Alpine.js on Hyva) and reads field definitions from the checkout configuration, not from the registration form layout. To show custom fields at checkout, you need a separate layout and fieldset definition in checkout_index_index.xml that references your EAV attribute. The backend save logic also differs because checkout saves to the order or quote, not to the customer entity. Many customer attribute extensions include checkout integration as an add-on feature.

Let us help you get started on a project with Custom Customer Registration Fields on Magento 2 and Hyva: EAV Attributes, Frontend Form Rendering, and Admin Grid Display and leverage our partnership to your fullest advantage. Fill out the contact form below to get started.

more articles about ecommerce

Read on the latest with Shopify, Magento, eCommerce topics and more.