Can anyone check this code and tell me how it is
and
is it usefull or not if not then how should i make it usefull.
source code is
CODE
<?php
/**********************************/
/***** Form Create using OOP *******/
/**********************************/
/**********************************/
class form {
//Input Attributes
public $type;
public $name;
public $value;
public $text;
public $opttext;
//Select Methods
public $optValues = array();
public $starttag;
public $action;
public $method;
/* form tag */
function formtag() {
if($this->starttag=='true') {
echo "<form action='". $this->action ."' method='". $this->method ."'>";
} else {
echo "</form>";
}
}
//Input Fields
function input() {
if($this->type=='text') {
echo $this->text."<input type='". $this->type ."' name='". $this->name ."' value='". $this->value ."'> ";
} else if ( $this->type=='select') {
echo $this->text."<select name='". $this->name ."'> ";
for($i=0; $i< count($this->optValues);$i++ ) {
echo "<option value='". $this->optValues[$i] ."'>". $this->optValues[$i] ." </option> ";
}
echo "</select>";
} else if($this->type=='radio' || $this->type=='checkbox') {
echo $this->text."<input type='". $this->type ."' name='". $this->name ."' value='". $this->value ."'>".$this->opttext;
} else if($this->type=='button' || $this->type=='submit') {
echo "<input type='". $this->type ."' name='". $this->name ."' value='". $this->value ."'> ";
} else {
echo "Please enter the type";
}
}//method end.
function br() {
echo "<br />";
}//if end
}//formFields class end.
$formInputs = new form;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>OOPs Form</title>
</head>
<body>
<?php
$formInputs->starttag='true';
$formInputs->action ='';
$formInputs->method ='post';
$formInputs->formtag();
$formInputs->text = "Name";
$formInputs->type = "text";
$formInputs->name = "";
$formInputs->value = "";
$formInputs->input();
$formInputs->br();
$formInputs->text = "DOB";
$formInputs->type = "text";
$formInputs->name = "";
$formInputs->value = "";
$formInputs->input();
$formInputs->br();
$formInputs->text = "Gender";
$formInputs->type = "radio";
$formInputs->name = "gender";
$formInputs->opttext = "Male";
$formInputs->input();
$formInputs->text = "";
$formInputs->type = "radio";
$formInputs->name = "gender";
$formInputs->opttext = "Female";
$formInputs->input();
$formInputs->br();
$formInputs->text = "Country";
$formInputs->type = "select";
$formInputs->name = "country";
$formInputs->optValues[] = 'Pakistan'; $formInputs->optValues[] = 'Afganistan'; $formInputs->optValues[] = 'usa';
$formInputs->optValues[] = 'Srilanka'; $formInputs->optValues[] = 'Malashia'; $formInputs->optValues[] = 'Rrussia';
$formInputs->input();
$formInputs->br();
$formInputs->type = "submit";
$formInputs->name = "";
$formInputs->value = "Submit";
$formInputs->input();
$formInputs->br();
$formInputs->starttag='false';
$formInputs->formtag();
?>
</body>
</html>