Jump to content

PHP OOP Help ? Class problems- variable ?


jd2007

Recommended Posts

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...

Link to comment
https://forums.phpfreaks.com/topic/64063-php-oop-help-class-problems-variable/
Share on other sites

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();

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.