5

I have config set to display 2 lines for address during checkout (Configuration → Customer → Customer Configuration → Name and Address Options):

Number of lines in a street address: 2

How can I make the second line a required field? Only the first field seems to be required. I've looked in the eav_attribute table & can't seem to find it listed there.

1 Answer 1

10

If you plan to make the second field mandatory for the checkout, you should make it mandatory in the customer add/edit address form for consistency.

For the client side validation you need to edit each template that holds an address for and add required-entry class on the second row. Here are the templates I found for this:

  • customer/form/address.phtml
  • customer/address/edit.phtml
  • persistent/customer/form/register.phtml
  • customer/form/register.phtml
  • checkout/onepage/billing.phtml
  • checkout/onepage/shipping.phtml
  • paypal/express/review/address.phtml
  • persistent/checkout/onepage/billing.phtml

As for server side validation you need to copy the file

app/code/core/Mage/Customer/Model/Address.php to the local folder /app/code/local/Mage/Customer/Model/Address.php. You cannot extend this class because the class is never instantiated.
And you need to add something in the validate method.

After this section:

    if (!Zend_Validate::is($this->getStreet(1), 'NotEmpty')) {
        $errors[] = Mage::helper('customer')->__('Please enter the street.');
    }

Add the validation for the second row

    if (!Zend_Validate::is($this->getStreet(2), 'NotEmpty')) {
        $errors[] = Mage::helper('customer')->__('Please enter the correct street.');
    }
5
  • is it the same in magento2? Commented Oct 19, 2016 at 15:36
  • I hnestly do not know.
    – Marius
    Commented Oct 19, 2016 at 16:23
  • Hi, the first part of this answer has been very helpful, however I couldn't find validate method in app/code/core/Mage/Customer/Model/Address.php My Magento version 1.9.1 any idea where it could be?
    – K.I
    Commented Mar 13, 2017 at 12:11
  • look for it in the parent classes of the address model.
    – Marius
    Commented Mar 13, 2017 at 12:13
  • How to remove validation for last name (customer address)in adminpanel.
    – Mahi M
    Commented Nov 10, 2017 at 7:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.