cancel
Showing results for 
Search instead for 
Did you mean: 

How to disable required field Last Name.

How to disable required field Last Name.

Hello every one.

I have an issue with the Customer fields. I try to remove Last Name field on the Register form then I submit the register form but it displays message  Last Name is  required. I checked  at table customer_eav_attribute and empty the validate_rules column of lastname field. 

Finally it does not work Smiley Sad.

Do you have any suggestion?

Thank you

6 REPLIES 6

Re: How to disable required field Last Name.

Go to the 'eav_attribute' table in magento database, Find for the 'lastname' in 'attribute_code' column and find 'is_required' column and set the value to 0 and try ro submit the  registration form

Elsner Technologies

Re: How to disable required field Last Name.

Hello @Nguyen Phuc

 

You need to change below file as well

Magento\Customer\Model\ResourceModel\CustomerRepository.php

if (!\Zend_Validate::is(trim($customer->getLastname()), 'NotEmpty')) {
            $exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'lastname']));
        }

Magento\Customer\Model\Customer.php

 

if (!\Zend_Validate::is(trim($this->getLastname()), 'NotEmpty')) {
            $errors[] = __('Please enter a last name.');
        }

you need to comment above file code.

 

Go to the 'eav_attribute' table in magento database, Find for the 'lastname' in 'attribute_code' column and find 'is_required' column and set the value to 0 and try ro submit the  registration form

 

If it will work then mark as solution.

 


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: How to disable required field Last Name.

Hi everybody, is this really considered the solution? I haven't done to much M2 frequently but hacking in some files or core modules and changing the database directly can't be a good solution for the "Best eCommerce Software for Selling Online", this sounds like M1. Of course you don't edit the core directly but shouldn't a simple task like setting a DEFAULT FORM field to required or not required be more easy and in the best case possible via the backend for the merchants? I'm not shooting at anybody (except maybe Magento) and open for other suggestions.

Re: How to disable required field Last Name.

But this is working in magento 1.9.For magento 2.1.12,what will be do?

 

Re: How to disable required field Last Name.

You can try the approaches from the start of this thread, I haven't tested it yet and was hoping for a better solution. How should a merchant be able to adjust the default form without knowing how to code?

Re: How to disable required field Last Name.

thank u