call a function
Posted: Sat Feb 04, 2006 3:44 pm
sorry for the vague title, not really sure how to sum this problem up.
I am making a class that creates and validates forms. On creating an input field in the form, I want to specify what validation function should be used for that field.
The validation check will probably be done by a function. That function will be defined in the class. I can't post the code as there's too much so I'll try and give an example.
My Class:
my form page where I make the form - and where the data posts back to (action is itself):
I want my data checker function in 'myFormClass' (not shown) to use the "vaildateEmail" function to check the data for that field. The only way my data checker function will know which function to use is because of this first element of the passed array.
I have considered using 'case' i.e. if the first element of the array == "vaildateEmail" then call that function. The reason I don't want to do that is because I just want to add new functions into my class as I need them without having to alter it in lots of places like switch statements.
Am I making any sense???
Thanks for the help in advance.
I am making a class that creates and validates forms. On creating an input field in the form, I want to specify what validation function should be used for that field.
The validation check will probably be done by a function. That function will be defined in the class. I can't post the code as there's too much so I'll try and give an example.
My Class:
Code: Select all
<?php
class myFormClass{
//...rest of the class up here
function vaildateEmail($email){
if( this is an $email ) ? return true : return false;
}
}
?>Code: Select all
<?php
$my_form = new myFormClass;
$my_form->makeAnInputField(various parameters here, array("vaildateEmail", "maybe another parameter..."));
?>I want my data checker function in 'myFormClass' (not shown) to use the "vaildateEmail" function to check the data for that field. The only way my data checker function will know which function to use is because of this first element of the passed array.
I have considered using 'case' i.e. if the first element of the array == "vaildateEmail" then call that function. The reason I don't want to do that is because I just want to add new functions into my class as I need them without having to alter it in lots of places like switch statements.
Am I making any sense???
Thanks for the help in advance.