RE: [PHP] Form Validating Class (OOP misunderstandings...)

From: Date: Tue, 21 Jan 2003 14:21:47 +0000
Subject: RE: [PHP] Form Validating Class (OOP misunderstandings...)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-132403@lists.php.net to get a copy of this message
PHP does not yet support private methods ... your problem with getValue() is most probably because register_globals is off in your php.ini try substituting $_POST[] for $HTTP_POST_VARS[] and it may start to work... HTH Rich -----Original Message----- From: Nicholas Wieland [mailto:nicholas_wieland@yahoo.it] Sent: 21 January 2003 14:13 To: php-general@lists.php.net Subject: [PHP] Form Validating Class (OOP misunderstandings...) Hello everybody, I'm working on a class but having a lot of problems... probably my understanding of PhP-OOP is not so good ... Here's the class: I found it on the web and I've tried to personalize it to fit my needs... <?php class FormV { var $errorList; function FormV() { $this->reset_errorList(); } function getValue( $field ) { $value = $HTTP_POST_VARS[ $field ]; return $value; } function isEmpty( $field, $msg ) { $value = $this->getValue( $field ); if( trim( $value ) == "" ) { $this->errorList[] = array( "field" => $field, "value" => $value, "msg" => $msg ); return true; } else return false; } function isString( $field, $msg ) { $value = $this->getValue( $field ); if( is_string( $value ) ) return true; else { $this->errorList[] = array( "field" => $field, "value" => $value, "msg" => $msg ); return false; } } function isEmail( $field, $msg ) { $value = $this->getValue( $field ); $pattern = "/^([a-zA-Z0-9])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/"; if( preg_match( $pattern, $value ) ) return true; else { $this->errorList[] = array( "field" => $field, "value" => $value, "msg" => $msg ); return false; } } function isError() { if( sizeof( $this->errorList ) > 0 ) return true; else return false; } function get_errorList() { return $this->errorList; } function reset_errorList() { $this->errorList = array(); } function stringConvert( $field ) { $value = $this->getValue( $field ); $value = html_special_chars( $value ); $value = stripslashes( $value ); $value = strtolower( $value ); return $value; } }; ?> Ok. I think that the getter is *totally* wrong but I'm not able to debug it, because it's private (I think...). Also the stringConvert() method sucks, maybe I'll split it in some others accessor methods, for a better design. Now I'm totally lost, I don't have a clue how to continue, I've tried for hours and hours to make it work, but didn't succeed :( Any suggestion on improving and other enhancment for a good form validating class is really really appreciated. TIA, Nicholas

« previous php.general (#132403) next »