Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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