Welcome Guest, Not a member yet? Register   Sign In
{field} placeholder does not get replaced with field name in a custom error message
#5

(04-17-2020, 07:23 AM)Gary Wrote: I think your |no_links| should probably be invoked like this:  |no_links[message]|

(04-17-2020, 09:24 AM)Gary Wrote: I think doing it that way forces all the fields to be pushed into an array, so that in your custom function (now defined like this:  function no_links(string $string, string $fields = NULL, array $data = NULL, string &$error = NULL) gets this array ($data), that has all the field names in it, from which you can extract {field} and insert it into the $error string your function is returning.

I stand under possible correction, but as far as I'm aware, the returned string is not processed any further, and pretty much gets displayed as is (with {field}).

Tried it but it does not seem to work; whatever I write in parentheses does not show up as an error message. But if I simplify the validation function thus:
PHP Code:
    public function no_links(string $string null): bool
    
{
        
$str preg_replace('/ /',''$string);
        
//$error = 'Lauke {field} negali būti nuorodų.';
        
if (strpos($str,'http')) { return false; }
        elseif (
strpos($str,'www')) { return false; }
        elseif (
strpos($str,'ftp')) { return false; }
        else {return 
true;}
    } 

and then append to my language validation file the error message key-value pair (file app/Language/lt/Validation.php):
PHP Code:
'no_links'             => 'Lauke {field} negali būti nuorodų.'

the function begins to work as expected. Only I do not want to modify the default language files to add new strings for my own rules...
==

Donatas G.
Reply


Messages In This Thread
RE: {field} placeholder does not get replaced with field name in a custom error message - by dgvirtual - 04-17-2020, 02:39 PM



Theme © iAndrew 2016 - Forum software by © MyBB