how can i add specific error message to specific custom field id?
My custom fields are text input and they are in address section.
Thanks in advance
version Opencart 3.0.3.3
litespeed , php 73
it is not an opencart default operation, you have to add or write a module for this.
take a visit to My Modules !
Thanks for the answer.
As you know custom fields are not really field they are arrays. i just try to call arrays from language file at the first try but not success. Any suggession?
thank you
You have to modify file upload/catalog/controller/account/address.php
in the function validateForm() there is the Custom field validation code,a quick and dirty solution (but i dont recommend it) is to change this value $this->language->get('error_custom_field') or write an extra else if for your custom field.
If you want to do it right and dont have future problems you can add (all with ocmod) a field "error_mesage" to the database table custom_field_description,
change in the model class account/custom_field getCustomFields method
and make some changes to method validateForm() of file upload/catalog/controller/account/address.php
in the function validateForm() there is the Custom field validation code,a quick and dirty solution (but i dont recommend it) is to change this value $this->language->get('error_custom_field') or write an extra else if for your custom field.
If you want to do it right and dont have future problems you can add (all with ocmod) a field "error_mesage" to the database table custom_field_description,
change in the model class account/custom_field getCustomFields method
and make some changes to method validateForm() of file upload/catalog/controller/account/address.php
take a visit to My Modules !
Thanks Wid for good ideas.Wid wrote: ↑Tue Jul 21, 2020 3:54 pmYou have to modify file upload/catalog/controller/account/address.php
in the function validateForm() there is the Custom field validation code,a quick and dirty solution (but i dont recommend it) is to change this value $this->language->get('error_custom_field') or write an extra else if for your custom field.
If you want to do it right and dont have future problems you can add (all with ocmod) a field "error_mesage" to the database table custom_field_description,
change in the model class account/custom_field getCustomFields method
and make some changes to method validateForm() of file upload/catalog/controller/account/address.php
i never touched controller files. Vue helped me alot.
i just written to address.twig file something like this :
<span class="text-danger" v-if="error && error.{{ type }}_custom_field && error.{{ type }}_custom_field[custom_field.custom_field_id] &&custom_field.custom_field_id == '1'" v-html="'{{ error_custom_field1 }}'"></span>
and of course does not touch core files made this with ocmod modification
and success
Sample Example to show checkout payment address custom field error:
If custom_field_id is 2 add error message in language
language>>en-gb>>checkout>>checkout.php
Add custom field error message in controller
controller>>checkout>>payment_address.php
like this you can use
If custom_field_id is 2 add error message in language
language>>en-gb>>checkout>>checkout.php
Code: Select all
$_['error_custom_field_for_id2'] = '%s required Must Be an alphabet!';
controller>>checkout>>payment_address.php
Code: Select all
if(($custom_field['custom_field_id']==2))
{
$json['error']['custom_field' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field_for_id2'), $custom_field['name']);
}
else {
$json['error']['custom_field' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
}
Who is online
Users browsing this forum: No registered users and 17 guests