jd2007 Posted August 9, 2007 Share Posted August 9, 2007 this is the class : <?php class FormProccess { function field($field) { $fields[]=$field; } function checkfill() { foreach ($fields as $fld) { if (empty($fld)) { $empty[]=$fld; } else { } } } function validatefill() { if (count($empty)>0) { return 1; } else { return 0; } } function notfilled() { return $empty; } function checkpass($pass, $cpass) { if ($pass==$cpass) { $re=1; } else { $re=0; } } } $form=new FormProccess $form->field("$_GET['username']"); $form->field("$_GET[pass]"); $form->field("$_GET[cpass]"); $form->field("$_GET[email]"); $form->checkfill(); $filled=$form->validatefill(); if ($filled==1) { $match=$form->checkpass(); if ($match==1) { echo "Success"; } else { echo "Passwords don't match."; } } else { echo "Please make sure all fields are filled !"; } ?> the class has functions to check if form fields are filled and checks if password and confirm password match...this is the form: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> </HEAD> <BODY> <FORM METHOD=GET ACTION="formclass.php"> Username: <INPUT TYPE="text" NAME="use"><BR> Password: <INPUT TYPE="text" NAME="p"><BR> Confirm Password: <INPUT TYPE="text" NAME="cp"> <INPUT TYPE="submit" VALUE="Submit"> </FORM> </BODY> </HTML> i plan to check if the form is not filled, wheter it echoes "Please make sure all fields are filled !"; the output i get is this: Parse error: syntax error, unexpected T_VARIABLE in C:\AppServ\www\formclass.php on line 59 pls help... Quote Link to comment https://forums.phpfreaks.com/topic/64063-php-oop-help-class-problems-variable/ Share on other sites More sharing options...
wildteen88 Posted August 9, 2007 Share Posted August 9, 2007 You have a missing ; or ) at the end of a line near line59. Change these lines: $form=new FormProccess $form->field("$_GET['username']"); $form->field("$_GET[pass]"); $form->field("$_GET[cpass]"); $form->field("$_GET[email]"); to: $form=new FormProccess; $form->field($_GET['username']); $form->field($_GET['pass']); $form->field($_GET['cpass']); $form->field($_GET['email]'); $form->checkfill(); Quote Link to comment https://forums.phpfreaks.com/topic/64063-php-oop-help-class-problems-variable/#findComment-319285 Share on other sites More sharing options...
jd2007 Posted August 9, 2007 Author Share Posted August 9, 2007 thanks..my output is this : Warning: Invalid argument supplied for foreach() in C:\AppServ\www\formclass.php on line 13 Please make sure all fields are filled ! what's wrong with my code ? Quote Link to comment https://forums.phpfreaks.com/topic/64063-php-oop-help-class-problems-variable/#findComment-319290 Share on other sites More sharing options...
emehrkay Posted August 9, 2007 Share Posted August 9, 2007 well looking at your code and your first two methods; fields and checkfill, it looks like check fill is using the array that is set in the fields method. is that correct? if it is, y ou need to set properties of the class - variables that only have a scope inside of the class. if youre using php4, class classname{ var $field = array(); //just so you know what kind of var it is supposed to be function fun($field){ $this->field[] = $field; } function checkfill(){ foreach($this->fields as ...){ ... } } } $this-> roughly means point to something within the scope of this class Quote Link to comment https://forums.phpfreaks.com/topic/64063-php-oop-help-class-problems-variable/#findComment-319327 Share on other sites More sharing options...
jd2007 Posted August 9, 2007 Author Share Posted August 9, 2007 if php5, what modifications to make.... Quote Link to comment https://forums.phpfreaks.com/topic/64063-php-oop-help-class-problems-variable/#findComment-319331 Share on other sites More sharing options...
emehrkay Posted August 9, 2007 Share Posted August 9, 2007 php example of the same code class classname{ public $fields = array(); //everything else is the same. public says that the variable is open to change from the instantiating call ie $x = new classname; $x->fields = 'whatever'; } Quote Link to comment https://forums.phpfreaks.com/topic/64063-php-oop-help-class-problems-variable/#findComment-319378 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.