Problems with Callback Functions and Validation Class |
[eluser]mariowarner[/eluser]
Hi guys, I've ran out of time, spent about 5 hours reading, debugging, reading, debugging but still haven't found any solution to my problem. I've used the code as stated on the user_guide about creating a callback function for a form validator but it just won't work on my server (although it did work on my local machine). If you guys can try and check out the website [ http://www.floralstyle.biz/ ], I have a pre-launch registration form which accepts an email address (simple) and a captcha input. My validation code looks like this: Code: $rules['cinput'] = "required|callback_cinputCheck"; No problems with the email and confirm email code. I only have problems with the callback_cinputCheck. Below is the cinputCheck function: Code: function cinputCheck($str) It's basically the same as the one on the user_guide's Validation Class (callback function). I just can't see why I keep getting the following error message when testing it online (while I don't get the same message offline): Code: Error(s): Does it have to do with server configurations? Cos I did upload all the CI files in a zip file and extracted it on the server to avoid BINARY/ASCII file upload problems. Any help will be greatly appreciated!
[eluser]Michael Ekoka[/eluser]
Try setting the field's name for cinput in the validation: Code: $fields['cinput'] = ''; If that doesn't work, could you tell us what version of CI you're using?
[eluser]mariowarner[/eluser]
Thanks for the reply! I'll try it now and tell you what happens.
[eluser]mariowarner[/eluser]
I'm still getting the same error. I'm using version 1.6.1. Do you think it's a bug? It does work on my machine (OS X 10.4.11 running Apache 1.3.33 and PHP 5.2.4. Does this have to do with the PHP version? I just checked my server's version and it's PHP 4.3.11.
[eluser]Michael Ekoka[/eluser]
I'm suspecting a problem with discrepancies between the case insensitive way php4 handles function names and the case sensitive hash values. Try renaming the function from cinputCheck to cinput_check and change the validation accordingly: Code: $rules['cinput'] = "required|callback_cinput_check";
[eluser]mariowarner[/eluser]
thanks. i did something similar to that before i renamed the function into cinputCheck. i named it captcha_check before. i'll try and do it again now, though, since i've finished with all the rest of the codes for the pre-launch phase - gives me time to check back on unsolvable problems (right now, just that part). coding in CI is really fast. i spent only about 3 hours from writing the codes for adding email addresses to the database, creating email template, sending confirmation email, creating the cancellation of subscription function. and that's all while reading the user_guide while working step-by-step. 'nuf said, i'll revise the code again and post the results here.
[eluser]mariowarner[/eluser]
hmm.. still didn't work. maybe i should change the way i handle the session variable into CI's way.
[eluser]Michael Ekoka[/eluser]
A little hack to help you for now: Code: function cinputCheck($str)
[eluser]mariowarner[/eluser]
Thanks, man! It still won't work so I did a different hack. I retained the original format of the callback function because it works on my local machine (in case the issue is not with CI but on the server configurations: Code: function cinputCheck($str) And then I did a string search for the error message generated by Validation Class in case it can't find an error message (this only works well with my codes because I know for sure that there's only one error that generates that error message): Code: // set validation rules Again, it might not work well with bigger forms with more than one callback function (cos i think the error has to do with Validation Class' callback functions), but it did the trick for now.
[eluser]maxez[/eluser]
I am new to CodeIgniter. I spent a day playing with both Cakephp and codeigniter, and decided for the former largely due to their validation flexibility. Now I am starting to unfortunately regret my decision! The validation class have several flaws that are only found when you run your code on PHP 4. Unfortunately I spent all my time coding on my PHP5 environment, only to find all kinds of problems when I built the app on my client's server running PHP4. The problem described above is just one of many problems found when moving the code to PHP4. I wish the code base would be fully tested on both PHP4 and PHP5 before claiming compatibility with both versions. Unfortunately, I cannot use that "hack" since I have TWO call back functions that are having the same problem. In addition, it is a horrible hack (I mean, my kudos to you for coming up with a solution, but it is still ugly ). I am at a loss on how to fix this short of having to get my hands dirty and try to "hack" the validation class myself (which will take a LONG time since I am not familiar with the inner workings of codeigniter). Any help will be greatly appreciated! Thanks, Max |
Welcome Guest, Not a member yet? Register Sign In |