Friday, September 14, 2012

PHP : Create Class INPUT TAG

<?
class Input{
var $json;
var $prop;
var $attr;
function Input(){}
function setProp($json='',$oldJson=''){
$this->json=$json;
if($oldJson!=''){
$merge=array_merge(json_decode($oldJson,true),json_decode($this->json,true));
$this->json=json_encode($merge);
}
$this->prop=json_decode($this->json,true);
$this->attr='';
foreach($this->prop as $key1=>$value1){
$this->attr.=strtoupper($key1).'=';
if(is_array($value1)){
$style='';
foreach($value1 as $key=>$value){
$style.=$key.':'.$value.';';
}
$this->attr.='\''.$style.'\' ';
}
else{$this->attr.='\''.$value1.'\' ';}
}
}
function getProp(){return $this->json;}
function setVisible($boolean=true){return '<INPUT '.$this->attr.'/>';}
}
$txt=new Input();
$txt->setProp('{
"type":"password",
"name":"txtUsername",
"id":"txtUsername",
"style":{"height":"30px","font-weight":"bold","border":"1px solid #0099FF"}
}');
print $txt->setVisible(true);
?>
Result              




มีตรงไหนสงสัยถามได้เลยนะครับ


BY N1B

No comments: