connect.php
test.php
php masters make this code better
PHP Code:
<?php
class connect
{
//$x = array("text-2","password-2","file-1","submit-1","lable-2");
function createform($method,$action,$enctype,$x)
{
echo $str = "<form method='".$method."' action='".$action."' enctype='".$enctype."'>";
foreach($x as $k=>$v)
{
$vdata = explode("-",$v);
if($vdata[0]=="text")
{
$i=1;
while($i<=$vdata[1])
{
$this->createtext("","","20",$vdata[0],1,"");$i++;
echo "<br />";
echo "<br />";
}
}
else if($vdata[0]=="password")
{
$i=1;
while($i<=$vdata[1])
{
$this->createtext("","","",$vdata[0],6,"");$i++;
echo "<br />";
echo "<br />";
}
}
else if($vdata[0]=="submit")
{
$i=1;
while($i<=$vdata[1])
{
$this->createtext("","Enter","",$vdata[0],1,"");$i++;
echo "<br />";
echo "<br />";
}
}
else if($vdata[0]=="file")
{
$i=1;
while($i<=$vdata[1])
{
$this->createtext("","","",$vdata[0],4,"");$i++;
echo "<br />";
echo "<br />";
}
}
else
{}
}
echo $str="</form>";
//echo $str;
}
function createtext($name,$value,$maxlength,$type,$fortype,$option)
{
if($fortype==1)
{
$str = "<input type='".$type."' maxlength='".$maxlength."' value='".$value."' name='".$name."' id='".$name."' class='".$name."' />";
}
else if($fortype==2)
{
$str = "<textarea maxlength='".$maxlength."' name='".$name."' id='".$name."' class='".$name."'> ".$value."</textarea>";
}
else if($fortype==3)
{
$str = "<select name=".$name.">";
if(count($option)>0)
{
foreach($option as $k=>$v)
{
$vdata = explode("-",$v);
$str.="<option value=".$vdata[0].">".$vdata[1]."</option>";
}
}
$str.= "</select>";
}
else if($fortype==4)
{
$str = "<input type='".$type."' value='".$value."' name='".$name."' id='".$name."' class='".$name."' />";
}
else
{
$str = "<input type='".$type."' value='".$value."' name='".$name."' id='".$name."' class='".$name."' />";
}
echo $str;
}
}
$obj=new connect;
?>
PHP Code:
<?php
// include_once("connect.php");
$x = array("text-2","password-2","file-1","submit-1","lable-2");
$obj->createform("post","action.php",5,$x);
?>
php masters make this code better
Comment