Magento – Magento 2 custom customer attribute’s values not getting saved in database

customer-attributemagento2

I've added two custom attributes for customer registration page (Alternate email & Alternate number) in a new module (through : app/code/…/Setup/InstallData.php).

I have designed its 'view' inside a custom theme (by overriding register.phtml). I can now see new fields on the registration page. However the data inside new fields (alternate email and number) is not getting saved inside database.

'customer_entity_int' saves '0' value..
'customer_entity_varchar' saves nothing..

enter image description here

Here in the screen you can see the value is saved as '0'. The attribute_id 132 is for 'Alternate Contact Number' on the registration page. So I expect the value to hold the data which I'm entering on the frontend registration page.

What am I doing wrong ?

Best Answer

You have probably solved your issue but for people who come here from google as me, there is a solution:

When creating the customer attribute, please take care of the following things:

Attribute is added to the attribute set, group

customer_eav_attribute
eav_entity_attribute

Attribute is assigned to customer forms

customer_form_attribute

And the last one the most important as somehow, people just skip over it and wondering why the customer attribute does not want to save from the backend: Please make sure to set "is_system" flag in "customer_eav_attribute" table to 0, otherwise the attribute will not be saved.

It can be done by setting the attribute option to "system" => 0 in attribute parameters inside the install/upgrade script.

Don't forget to flush your cache after all!

Solution URL:

direct link to solution

Related Topic