Guest convention Posted December 26, 2006 Share Posted December 26, 2006 I'm fairly new to OOP programming in PHP, so I need some help working this out.I created a class which contains a function to validate a regular form input field. Notice how in the class below, the first if statement determines whether the form button is pressed or not. When I instantiate the class and use the if statement (if ($check)...), the 'Error.' echoes even before the form button is pressed, even though I made it clear to check that in the class.[code=php:0]class formVal { var $button; var $field; var $len; function allChars() { if (isset($this->button)) { if (strlen($this->field) >= $this->len) { return (true); } else { return (false); } } }}[/code]---------------------------------------------------------------------[code=php:0]$testform = new formVal;$testform->button = $_POST['submit']; $testform->field = $_POST['field1']; $testform->len = 5;$check = $testform->allChars();if ($check) { echo 'Passed!';} else { echo 'Error.';}[/code]How can I fix this problem? Link to comment https://forums.phpfreaks.com/topic/31860-form-validation-class-not-working-properly/ Share on other sites More sharing options...
btherl Posted December 26, 2006 Share Posted December 26, 2006 You don't specify a return value for allChars() in the case where $this->button is not set. That could be the problem. Link to comment https://forums.phpfreaks.com/topic/31860-form-validation-class-not-working-properly/#findComment-147832 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.