CodeIgniter Forums
Displaying Validation errors - with more than a single {parm} - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Displaying Validation errors - with more than a single {parm} (/showthread.php?tid=78050)



Displaying Validation errors - with more than a single {parm} - Gary - 11-24-2020

Here’s an easy one, to which I suspect the answer is “No”:

Is there a way that custom validation error messages can be customised to have MORE than a single {parm} injected into it?

The examples in the CI user guide indicate a possibility of having three fields injected in to the return: {value}, {field} and {parm}.  Many of the checks have only a single parameter to be checked, however there are some (like max_dims[]) that have two… and even if one uses the same variable name for the width and height, is still fails to inject the custom-spec’d number into {parm}:

Code:
In Validation:

'file' => [
'label' => …
'rules' => '…|max_dims[file_field,'.self::IMAGE_WIDTH_MAX','.self::IMAGE_HEIGHT_MAX_PX.']|…',
]

In the language error messages file:

'image' => [
  'file.label' => 'image',
  …
  'file.max_dims' => 'The {field} file dimensions cannot exceed {parm}x{parm}px',
]

* I know there are other easy ways around this, but these effectively break/circumvent the mindset/consistent (and simple) manner that all the other parameter injections are done, making it a (frequently used) special case, which bothers me.