Following code easy to understand made html form using php oops concept
<?php
/***** HTML 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' || $this->type=='reset') {
echo "<input type='". $this->type ."' name='". $this->name ."' value='". $this->value ."'> ";
}
else if($this->type=='textarea') {
echo $this->text."<textarea wrap='virtual' name='". $this->name ."'>". $this->value ."</textarea>";
}
else {
echo "Please enter the type";
}
}//method end.
function br() {
echo "<br />";
}//if end
}
$formInputs = new form;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<TITLE>OOPs HTML Form</TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</head>
<body>
<h1>HTML Form using oops </h1>
<?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[] = 'India'; $formInputs->optValues[] = 'UK'; $formInputs->optValues[] = 'usa';
$formInputs->optValues[] = 'Srilanka'; $formInputs->optValues[] = 'Bhutan'; $formInputs->optValues[] = 'Tibet';
$formInputs->input();
$formInputs->br();
$formInputs->text = "Message";
$formInputs->type = "textarea";
$formInputs->name = "message";
$formInputs->input();
$formInputs->br();
$formInputs->type = "submit";
$formInputs->name = "";
$formInputs->value = "Submit";
$formInputs->input();
//$formInputs->br();
$formInputs->type = "reset";
$formInputs->name = "";
$formInputs->value = "Clear";
$formInputs->input();
$formInputs->br();
$formInputs->starttag='false';
$formInputs->formtag();
?>
</body>
</html>
<?php
/***** HTML 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' || $this->type=='reset') {
echo "<input type='". $this->type ."' name='". $this->name ."' value='". $this->value ."'> ";
}
else if($this->type=='textarea') {
echo $this->text."<textarea wrap='virtual' name='". $this->name ."'>". $this->value ."</textarea>";
}
else {
echo "Please enter the type";
}
}//method end.
function br() {
echo "<br />";
}//if end
}
$formInputs = new form;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<TITLE>OOPs HTML Form</TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</head>
<body>
<h1>HTML Form using oops </h1>
<?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[] = 'India'; $formInputs->optValues[] = 'UK'; $formInputs->optValues[] = 'usa';
$formInputs->optValues[] = 'Srilanka'; $formInputs->optValues[] = 'Bhutan'; $formInputs->optValues[] = 'Tibet';
$formInputs->input();
$formInputs->br();
$formInputs->text = "Message";
$formInputs->type = "textarea";
$formInputs->name = "message";
$formInputs->input();
$formInputs->br();
$formInputs->type = "submit";
$formInputs->name = "";
$formInputs->value = "Submit";
$formInputs->input();
//$formInputs->br();
$formInputs->type = "reset";
$formInputs->name = "";
$formInputs->value = "Clear";
$formInputs->input();
$formInputs->br();
$formInputs->starttag='false';
$formInputs->formtag();
?>
</body>
</html>
No comments:
Post a Comment