This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

doobyeee10080
doobyeee10080

Hi,

I use the validator system for my contact form in front End with an array custom attributes :


public $customAttributes = [
        'name' => 'helin.contact::lang.label.name',
 ];

$validator = Validator::make($data, $this->formValidationRules, $this->customMessages, $this->customAttributes); 

For the moment in front-end, it displays : The helin.contact::lang.label.name field is required. Instead of : The Name field is required.

How can I do this ? Thank you.

Last updated

chris10207
chris10207

Hi did you try with something like this :

e(trans('helin.contact::lang.lang.message'))

Of curiosity, im trying to handle custom fields / attributes as well for my application, could you share a bit how you manage this part please ?

thanks in advance

doobyeee10080
doobyeee10080

Hi,

Thank you. I finally moved my array in my method and it works. For custom fields / attributes, you can use this :


    /**
     * Contact form validation rules.
     */
    public $formValidationRules = [
        'firstname' => 'required',
        'lastname' => 'required'
    ];

    /**
     * Custom message.
     */
    public $formCustomMessage = [
        'firstname.required' => 'Please don\'t forget your :attribute !',
        'lastname.required' => 'Please don\'t forget your lastname !'
    ];

    /**
     * Contact form attributes pretty.
     */
    public $formCustomAttributes = [
        'firstname' => 'Firstname',
    ];

    //Validation
    $validator = Validator::make($data, $this->formValidationRules, $this->formCustomMessage, $this->formCustomAttributes);
Eoler
Eoler

What are the global (Laravel/OctoberCMS) localization files with model validation messages? How can those be translated on the frontend (which functions in Twig and CMS event handlers)?

1-4 of 4

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.