|
![Picture of Paul Handforth Picture of Paul Handforth](/graphics/unknown.gif) Paul Handforth - 2011-02-22 16:19:37
Manuel
Thank you - I have been using your excellent class for a form I am working on and have nearly completed it apart from one final problem.
I have a form field "user name" in which I want the user to enter a value which is unique and has not been used before, based on records in a MySQL table.
I have looked through the documentation but I have not been able to find how to do this based on the MySQL examples available.
I saw "ValidationServerFunction" and wondered if I could use this but I cannot find details of how to use this function.
Did I miss something or misunderstand how it is done...?
If it is already possible to do this uniqueness checking, please would you point me in the right direction of how to do it...?
Regards
Paul
![Picture of Manuel Lemos Picture of Manuel Lemos](/picture/user/1.jpg) Manuel Lemos - 2011-02-22 20:27:31 - In reply to message 1 from Paul Handforth
Actually you have three ways of doing it:
1. Use the ValidateServerFunction to specify a global function to make the necessary verifications and return 0 in case your user name is not unique.
2. Use a custom plug-in class to do the validation. Take a look at the test_custom_validation.php and form_custom_validation.php example scripts.
3. Call the class Validate function to perform all basic validations first and if it passes, perform your unique user checks and if the user name is duplicated use the class FlagInvalidInput to inform which form field is invalid and the associated error message.
![Picture of Paul Handforth Picture of Paul Handforth](/graphics/unknown.gif) Paul Handforth - 2011-02-23 17:08:41 - In reply to message 2 from Manuel Lemos
Hi Manuel
Thank you for the fast reply!!
With the first option you gave: I have been trying to use the ValidateServerFunction and cannot get the validation to fail. I have made my validation function as simple as a single line:
function ValidateUserName()
{
return false;
}
.. to try and force a validation error but it seems to pass the through the validation every time and submit the form successfully. I do not know if I am missing something basic. I added the function at the top of the same PHP, just before I declared the form inputs etc. In the user_name form input, I added the lines:
"ValidateServerFunction"=>"ValidateUserName",
"ValidateServerFunctionErrorMessgae"=>"Validation failed",
...but the form still passes validation.
The third option you gave, I didn't understand enough to try it. But the second option, the custom plug-in class, seems most flexible. I have spent most of today trying to get a custom plug-in class to work - without success...
I took an exact copy of your form_custom_validation.php file and renamed the class within to personal_custom_validation_class. My first input name is "user_name". I added a second field to the form "user_name2" as the SecondInput and got it working correctly, comparing the values of "user_name" and "user_name2" and flagging an error when either field contained the other. i.e. a got a duplicate of your program working on my server so I could work from there and make my own changes (to check for a unique user name)...
...so one of my first changes is that I do not need the client side validation (because the MySQL checking is server side only), so I set the value of the line near the top of the validation class to:
var $client_validate=0;
With just this simple change, there is no longer a validation error flagged and the form passes validation, when it should fail on server side checking. It seems like the class is not performing any server side validation for me. I even changed part of the Function ValidateInput() function, commenting out the lines:
if(strlen($first)
&& strstr($second, $first))
..and replacing with:
if(true)
...trying to force a validation failure. But the form passes validation each time.
Am I misunderstanding something very basic here...? I've spent many hours trying to work out the solution but there is something I am doing wrong I'm sure. Are you able to see from what I've typed what the error I'm making...?
Regards
Paul
![Picture of Manuel Lemos Picture of Manuel Lemos](/picture/user/1.jpg) Manuel Lemos - 2011-02-24 08:57:40 - In reply to message 3 from Paul Handforth
Sorry the correct names of the options are ValidationServerFunction and ValidationServerFunctionErrorMessage.
To use the custom validation plug-in class on the server side, you need to keep the server_validate variable set to 1 and make sure you call AddInput function to add the custom validation input before you call Validate.
The third option is just to do whatever validation checks you want right after calling Validate and it says all fields are valid. If your unique user checks fail, just call FlagInvalidInput to tell the class to consider the user name input as invalid.
![Picture of Paul Handforth Picture of Paul Handforth](/graphics/unknown.gif) Paul Handforth - 2011-02-24 18:15:49 - In reply to message 4 from Manuel Lemos
Hi Manuel
Thank you so much for your help. Your fast answers enabled me to see that I had done nearly everything right, except I had made a simple omission regarding the "doit" hidden field... Although I had specified it as an input, I had not placed it using the html and hence the server side validation was never activated. A very basic error on my part.
Anyway I now have 2 different types of validation working just fine (options 2 & 3) so I'm very happy :-)
Thank you again for all your help and for the vast effort you have put into making this class such an excellent tool.
Regards
Paul
|