Custom validation callback function is not being triggered by set_rules() function.
Am i missing something?
Custom Validation Callback function is not being triggered
4 years ago
4 years ago
#1
4 years ago
#2
Hi there,
The callback is working but the reason you aren't seeing it is you are loading your view over the error msg and you're not setting any rules so you will always get a validation error_msg with the code you shared.
move validation_errors(); into your view
Try this for fun and enter '[email protected]' as an email
The callback is working but the reason you aren't seeing it is you are loading your view over the error msg and you're not setting any rules so you will always get a validation error_msg with the code you shared.
move validation_errors(); into your view
Try this for fun and enter '[email protected]' as an email
4 years ago
#3
No that is not the case. "required | valid_email" is working fine and giving error if needed, only "callback_" function is not giving error message.
Please check below POC.
VIEW FILE
Email
CONTROLLER FILE
Edit: I don't know why my view file is being truncated while posting here, please check below link.
View file:- https://justpaste.it/6i2w9
Please check below POC.
VIEW FILE
CONTROLLER FILE
Edit: I don't know why my view file is being truncated while posting here, please check below link.
View file:- https://justpaste.it/6i2w9
4 years ago
#4
Found the problem and raised a issue on github: https://github.com/davidjconnelly/trongate-framework/issues/88
4 years ago
#5
Hi eleetgeek,
When pasting your code, you have to replace all HTML entity tags, see https://www.w3schools.com/html/html_entities.asp
Like this for your welcome.php view file, which you have called 'login' above
Your controller, view (form) and submit (method) is not correctly setup. I'd suggest you create a module with the Desktop app to see how it would be better structured.
However let's see if we can get your code working.
Your controller should look like this:
As I said above, the custom call back needs to return 'true' or an 'error_msg' to be useful, otherwise it will always return an error_msg as above.
Change your callback to this and enter '[email protected]' for an error_msg and anything else for a 'well done' response
When pasting your code, you have to replace all HTML entity tags, see https://www.w3schools.com/html/html_entities.asp
Like this for your welcome.php view file, which you have called 'login' above
Your controller, view (form) and submit (method) is not correctly setup. I'd suggest you create a module with the Desktop app to see how it would be better structured.
However let's see if we can get your code working.
Your controller should look like this:
As I said above, the custom call back needs to return 'true' or an 'error_msg' to be useful, otherwise it will always return an error_msg as above.
Change your callback to this and enter '[email protected]' for an error_msg and anything else for a 'well done' response
4 years ago
#6
I understand what you are trying to explain.
Problem is callback_function is not getting trigger if "view endpoint" and "form action endpoint" is same. In this case inbuilt set_rules() are working fine, just callback_function is not working (always returns true or not being trigger)
Problem is callback_function is not getting trigger if "view endpoint" and "form action endpoint" is same. In this case inbuilt set_rules() are working fine, just callback_function is not working (always returns true or not being trigger)
4 years ago
#7
It looks like you have different names.
You are trying to call callback_otp_custom
Your function is otp_custom
Updated
Sorry, did not see that
https://trongate.io/docs_m/information/custom-validation-callbacks
Dan
You are trying to call callback_otp_custom
Your function is otp_custom
Updated
Sorry, did not see that
https://trongate.io/docs_m/information/custom-validation-callbacks
Dan
4 years ago
#8
Syntax is correct, please check the documentation https://trongate.io/docs_m/information/custom-validation-callbacks
4 years ago
#9
Attaching a POC: https://www.mediafire.com/file/kic6qln7ykuooa0/custom_validation_test.zip/file
Please have a look.
Please have a look.
4 years ago
#10
Thanks for sharing that zip file, it helped a lot and I have the solution.
The problem is you were testing the validation helpers callback_ from the Welcome controller, which when I looked into the validation_helper.php 'attemp_invoke_callback() it was trying to get the module name from the first segment, which is null and I was confused because I was testing it from a new module.
This doesn't work
This does, as 'test_validation' is segment(1)
The patch to make it work without a segment(1), index of the default Controller is right after line 457 of the 'validation_helper.php'
add this to line 458
attempt_invoke_callback() should now look like this
The problem is you were testing the validation helpers callback_ from the Welcome controller, which when I looked into the validation_helper.php 'attemp_invoke_callback() it was trying to get the module name from the first segment, which is null and I was confused because I was testing it from a new module.
This doesn't work
This does, as 'test_validation' is segment(1)
The patch to make it work without a segment(1), index of the default Controller is right after line 457 of the 'validation_helper.php'
add this to line 458
attempt_invoke_callback() should now look like this