![]() |
acessing multiple methods....
Is there any way to access multiple methods so you don't have to type the variable you're checking against over and over?
For example, instead of this: PHP Code:
So I tried this, but it didn't work. PHP Code:
|
Perhaps write another method which takes the variable and a list of checks.
PHP Code:
|
Quote:
PHP Code:
And hopefully the class method doesn't get too big and bloated looking... |
1 Attachment(s)
Building upon Salathe's idea, I came up with the following which may well work:
php Code:
Then of course to use that you would simply do: php Code:
If you want me to explain the code, please ask! I don't know if it's understandale or not, as it is. |
Quote:
I just started re-coding my class based on Sal's suggestion. I'll take a look at yours since it builds off of his suggestion. Quickly glancing it, I think I do get it... ^^ |
Ok, I do have some questions.
1)You create constants so you can call them statically from the main script. Then pass them as arguments in the isValid() function. How are you able to pass in extra arguments when it's not defined in the function? Or does PHP loosely allow you to add optional arguments without have to specify them when creating the functions? And if so, does this work for regular functions too or just class methods? 2) $bValidated is set to false. Why do we do this? Is this because we have to declare every property in the class before using it? 3) array_shift($aArgs). Since in your example, you passed 3 arguments to the isValid function and then do a foreach loop on the array $aArgs, are you shifting to the 2nd element so that the foreach starts from there, so basically all we get are the 2 constants: NOT_EMPTY and IS_EMAIL....? 4) After checking if a method exists, I'm a little unclear on what we do here. We set: $bValidated = $this->$szFunction($szVariable); I don't see any methods called: $szFunction, so I'm not sure what is going on here. 5) We then do this: PHP Code:
6) Since the other methods are set to private. Is the isValid method basically our "getter" method? |
Ok, I understand #4 now...
PHP Code:
Then passes the actual data, so that the method actually gets called... DUH! |
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
|
Quote:
Quote:
This is the first time I've seen it used for functions. Very tricky....gotta keep an eye out for this in the future... Quote:
The way I am seeing it, (which is probably wrong) is this: if(!false) return true; Quote:
Here's what I have working so far. Obviously the layout is a quick hack....but it's functioning! http://www.gatebattle.com/form.html What I am going to try to do next is provide the error info next to each input element so you know what the actual error status is talking about, instead of just listing it. |
Here's my class. As you can see, it has parts of what WH provided earlier on...
I have some issues with this which I will be working on. 1) There's no way yet to correlate the errors with the data input. So right now all the errors get thrown into an array and then just printed out. 2) The string length check is minimum of 6. Not sure if this is good to be hardcoded. 3) Need to have a characters range method. 4) Sanitizing data input from SQL injects and buffer overflow. Don't know if this belongs in the validation class, or the database class. 5) Checking for existence of username/email already in the system. PHP Code:
|
BTW, this is what my main script looks like:
PHP Code:
|
Quote:
$bValidated shouldn't remain false. If all is well, it'll be changed to true from either of the two private functions.php Code:
If it's still false after that then it failed validation. |
Quote:
Basicly PHP Code:
PHP Code:
|
| All times are GMT. The time now is 04:49 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0