How to make the company field and state field in the address form (in admin panel, Customer->Manage Customer->new Customers) mandatory when a user is created. I tried to find a phtml corresponding to the form, but dint find any. Also how to make just the js validation for the company and state field?
1 Answer
The customer fields are based on EAV which means an individual field can't be found in the template files but is stored in the database as an attribute.
In this case it's the customer_eav_attribute
table. But first you'll need to know the attribute ID. For that check the eav_attribute
table, locate your attribute and use the attribute_id
value to locate the correct row in the customer_eav_attribute
table.
Also set is_required
to 1 for this attribute in the table.
If you take a look at the customer_eav_attribute
table you'll see a couple of columns, for your question the validate_rules
column is the important one. It contains a serialized array with the types of validation.
To make a field simply required adding a:2:{s:15:"max_text_length";i:255;s:15:"min_text_length";i:1;}
should be enough.
I haven't tested this so I'd suggest testing it on a development environment first.
-
1how about setting
is_required=1
whereattribute_code=company
in the tableeav_attribute
Commented Jul 10, 2015 at 11:52 -
but this will make the company field required at all the places, frontend and backend as well. Commented Jul 10, 2015 at 12:27
-
is_required error is comming, so once the user enter everything and press save, after reloading magento will show the error. But the js validation is not working by modifying the validate rules.– tedCommented Jul 10, 2015 at 12:39
-
Surprisingly some fields are without the validation rules in db are required fields!!!– tedCommented Jul 10, 2015 at 12:42