<?php

class Text_Apank_Form
{
	protected $ext = 'text';
	
	public function createForm($data, $name, $no, $label)
	{
		$input = "<input type='".$this->ext."' id='$name'";
		foreach($data as $key => $row){
			if($key == 'class'){
				$row = $this->ext." urut_$no ".$row;
			}
			$input.= " $key='$row'";
		}
		
		$input.= " class='".$this->ext." urut_$no' no='$no' label='$label'> <div id='errorApank$name' class='errorApankform'></div>";
	
		return $input;
	}
	
	public function addAttrib($form, $param, $val)
	{
		$ex = explode(' <div ', $form);
	
		$form = str_ireplace("<input type='".$this->ext."' ", '', $ex[0]);
		$form = str_ireplace(' >', '', $form);
		
		$attr = '';
		$n = explode("' ", $form);
		foreach($n as $i){
			$i = str_ireplace("'", '' , $i);
			$a = explode('=', $i);
			if(strtoupper($a[0]) == strtoupper($param)){
				$attr.= "$param='$val' ";
			}else{
				$attr.= $a[0]."='".$a[1]."'";
			}
		}
		
		$form = "<input type='".$this->ext."' $attr $param='$val'> <div ".$ex[1];
		return $form;
	}
}