Class/functions question
| From: | Paul Goepfert | Date: | Sun, 12 Feb 2006 05:31:50 +0000 |
| Subject: | Class/functions question | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-230262@lists.php.net to get a copy of this message | ||
Hi all,
I building a website with PHP. I am going to be using functions to
deal with vaildation. I am putting all the methods in a class called
Validation. My problem is I do not know how to call the function.
Well I shouldn't say that. I know how to call functlions, I just just
don't know how to do it in PHP. Let me put it this way. When I write
programs in C++/Java I know that I have to do the following steps,
create an object reference to the class
use the object reference to access the methods.
I am almost certain that it is the same thing in PHP. So this is what
I did in my web page.
<?php
if (isset($submit))
{
//validation code
class Validation
{
function checkEmpty ($var)
{
if (empty($var))
{
echo "YEAH It works!!";
}
}
}
else
{?>
.....
<tr>
<td align="left">First Name</td>
<td align="left">
<span class="color">*</span><input type="text"
name="name" size="20">
<?php
$v = new Validation;
$v->checkEmpty($_POST["name"]);
?>
</td>
</tr>
......
... = rest of php/html code
the else block holds the entire html code for the page
Do I have the logic right?
Paul