Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I add an error message for a validation method created in a class that extends GUMP? #332

Closed
Joelfo opened this issue Jul 9, 2022 · 2 comments

Comments

@Joelfo
Copy link

Joelfo commented Jul 9, 2022

I want to simply add a specific error message to appear if the validation function created inside the class return false. How can I do this? The instructions on the README.md do not seem to cover this issue.
Thanks!

@filisko
Copy link
Collaborator

filisko commented Jul 14, 2022

@Joelfo yes it does cover it.

https://github.com/Wixel/GUMP#other-available-methods

// Set custom error messages for rules.
GUMP::set_error_message('required', '{field} is required.');
GUMP::set_error_messages([
    'required'    => '{field} is required.',
    'valid_email' => '{field} must be a valid email.'
]);

just replace GUMP with your class.

@filisko filisko closed this as completed Jul 14, 2022
@j-masci
Copy link

j-masci commented Oct 27, 2022

I'm not understanding why the error messages are static, we should be able to set custom everything on a per-instance basis when needed. With extending the class and adding filter_* and validate_* methods, you can set custom filters/validators on a per instance basis, but then why do the error messages associated with those validators have to be global? I would like to be able to make a function that returns me a gump instance specific for my needs, without affecting all other gump instances used in the same project. I don't know if some reflection tricks can somehow accomplish this but its not something I've ever done. @filisko

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants