Post by kerim92 » Tue Jul 21, 2020 7:14 am

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

Newbie

Posts

Joined
Tue Apr 09, 2013 2:50 am

Post by Wid » Tue Jul 21, 2020 2:58 pm

it is not an opencart default operation, you have to add or write a module for this.

take a visit to My Modules !


Wid
New member

Posts

Joined
Fri Feb 02, 2018 9:19 pm
Location - Athens/Greece

Post by kerim92 » Tue Jul 21, 2020 3:39 pm

Wid wrote:
Tue Jul 21, 2020 2:58 pm
it is not an opencart default operation, you have to add or write a module for this.
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

Newbie

Posts

Joined
Tue Apr 09, 2013 2:50 am

Post by Wid » Tue Jul 21, 2020 3:54 pm

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

take a visit to My Modules !


Wid
New member

Posts

Joined
Fri Feb 02, 2018 9:19 pm
Location - Athens/Greece

Post by kerim92 » Tue Jul 21, 2020 8:46 pm

Wid wrote:
Tue Jul 21, 2020 3:54 pm
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
Thanks Wid for good ideas.

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

Newbie

Posts

Joined
Tue Apr 09, 2013 2:50 am

Post by i.am.retailer » Sat Jul 25, 2020 1:54 pm

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

Code: Select all

$_['error_custom_field_for_id2']             = '%s required Must Be an alphabet!';
Add custom field error message in controller

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']);
}
like this you can use

New member

Posts

Joined
Thu Jun 04, 2020 2:10 pm
Who is online

Users browsing this forum: No registered users and 32 guests