|
|
|
class create input (text , password , button , reset , submit , textarea , select) |
|
|
|
|
|
|
|
ผมทำเอาไว้ใช้งานเลยเอามาแบ่งเผื่อ มีใครต้องการ
Code (PHP)
<html><head><title></title></head><body>
<?php
/* index.php
create text, password, button, submit, reset, textarea, select, radio, checkbox
support javascript
ทำงานผ่าน array การเรียงค่าเช็กจากใน array
*/
$param = array( 'query_sent' => array(
'type' => array('checkbox','select' , 'radio' , 'button' , 'select' , 'text'), //input type
'textid' => array('001' , '002' , '003' , '004' , '005' , '006'), //id name
// 'copy' => false , // option
'class' => array('001','002' , '003' , '004' , '005' , '006'), //class
'val' => array('00001','00002' , '00003' , '00004' ,'00005' , '00006'), //value input
'option_select' => array("",array('test01','test02'),"","",array('test03','test04'),""), //option input select
'onclick' => array('','','',array('sent' , array('002','001')),"","")//สำหรับส่งตัวแปลไปที่ javascript array('sent' , array('002','001')) sentคือชื่อฟังชั้น array('002','001') คือตัวแปลที่ฟั้งชั้นส่งไป
)
);
$input = new createinput($param['query_sent']);
$input->queryinput(999);//ถ้า option = 999 จะสร้าง input ออกมาทั้งหมด
echo "<br />";
$input->queryinput(0);//ถ้า option = 0 จะสร้าง input checkbox ออกมา
echo "<br />";
$input->queryinput(2);//ถ้า option = 2 จะสร้าง input radio ออกมา
echo "<br />";
$input->queryinput(5);//ถ้า option = 5 จะสร้าง input radio ออกมา
?>
</body></html>
Code (PHP)
<?php //class.php
class createinput{
var $template = ""; //ตัวแปร input
var $textid = ""; //คัวแปร id และ namr
var $num = ""; //ตัวแปร สำหรับการ query input ทั้งหมด
var $type = ""; // ตัวแปร type ของ input
var $classinput = ""; // ตัวแปร class
var $option_select = ""; // ตัวแปร Option ของ select
var $onclick = ""; // onclick สำหรับ javascript
var $valuesent = ""; // ตัวแปร value
var $params;
public function __construct($param)
{ $this->params = $param;
}
public function queryinput($query)
{
$param = $this->params;
$this->type = $param['type'];
$this->textid = $param['textid'];
$this->classinput = $param['class'];
$this->ovalue = $param['val'];
$this->option_select = $param['option_select'];
$this->onclick = $param['onclick'];
$this->template = "";
$this->num = count($this->type)-1;
if($query == 999)
{ for($i=0;$i<=$this->num;$i++) //loob create input
{ switch($this->type[$i])
{
case 'text' :
case 'password' :
case 'submit' :
case 'button' :
case 'reset' :
case 'checkbox' :
case 'radio':
if($this->onclick[$i] != ""){
foreach($this->onclick[$i][1] as $key => $value)
{ if($key == 0){
$this->valuesent .= $value;}
else{ $this->valuesent .= ",".$value;}
}
$this->template .= "<input onclick=".$this->onclick[$i][0]."(".$this->valuesent."); type=".$this->type[$i]." id=".$this->textid[$i]." name=".$this->textid[$i]." class=".$this->classinput[$i]." value=".$this->ovalue[$i]." />";
}
else{
$this->template .= "<input type=".$this->type[$i]." id=".$this->textid[$i]." name=".$this->textid[$i]." class=".$this->classinput[$i]." value=".$this->ovalue[$i]." />";
}
break;
case 'textarea' :
switch($this->textid[(int)$query])
{
case 'detailth' :
$this->template .= "<".$this->type[$i]." id=".$this->textid[$i]." name=".$this->textid[$i]." class=".$this->classinput[$i].">".$this->ovalue[$i]."</textarea>";
break;
case 'detailen' :
/* if($param['copy'] == true)
{
$this->template .= "<img id='copy' src='images/text-copy-txteditor.jpg' title='Copy text language :: Thai to English' onclick='gettext();' style='cursor:pointer;' />";
} */
$this->template .= "<".$this->type[$i]." id=".$this->textid[$i]." name=".$this->textid[$i]." class=".$this->classinput[$i].">".$this->ovalue[$i]."</textarea>";
break;
default :
$this->template .= "<".$this->type[$i]." id=".$this->textid[$i]." name=".$this->textid[$i]." class=".$this->classinput[$i].">".$this->ovalue[$i]."</textarea>";
break;
}
break;
case 'select' :
$this->template .= "<".$this->type[$i]." id=".$this->textid[$i]." name=".$this->textid[$i].">";
foreach($this->option_select[$i] as $key => $value)
{
$this->template .= "<option id=".$key.">".$value."</option>";
}
$this->tamplate .= "</".$this->type[$i].">";
break;
}
}//end loob create input
}
else if($query != 999)
{ switch($this->type[(int)$query])
{ case 'text' :
case 'password' :
case 'submit' :
case 'button' :
case 'reset' :
case 'checkbox' :
case 'radio':
//new create input
if($this->onclick[(int)$query] != ""){
foreach($this->onclick[(int)$query][1] as $key => $value)
{ if($key == 0){
$this->valuesent .= $value;}
else{ $this->valuesent .= ",".$value;}
}
$this->template .= "<input onclick=".$this->onclick[(int)$query][0]."(".$this->valuesent."); type=".$this->type[(int)$query]." id=".$this->textid[(int)$query]." name=".$this->textid[(int)$query]." class=".$this->classinput[(int)$query]." value=".$this->ovalue[(int)$query]." />";
}else{
$this->template .= "<input type=".$this->type[(int)$query]." id=".$this->textid[(int)$query]." name=".$this->textid[(int)$query]." class=".$this->classinput[(int)$query]." value=".$this->ovalue[(int)$query]." />";
}
break;
case 'textarea' :
switch($this->textid[(int)$query])
{ case 'detailth' :
$this->template .= "<".$this->type[(int)$query]." id=".$this->textid[(int)$query]." name=".$this->textid[(int)$query]." class=".$this->classinput[(int)$query].">".$this->ovalue[$i]."</textarea>";
break;
case 'detailen' :
/* if($param['copy'] == true)
{
$this->template .= "<img id='copy' src='images/text-copy-txteditor.jpg' title='Copy text language :: Thai to English' onclick='gettext();' style='cursor:pointer;' />";
} */
$this->template .= "<".$this->type[(int)$query]." id=".$this->textid[(int)$query]." name=".$this->textid[(int)$query]." class=".$this->classinput[(int)$query].">".$this->ovalue[$i]."</textarea>";
break;
}
break;
case 'select' :
$this->template .= "<".$this->type[(int)$query]." id=".$this->textid[(int)$query]." name=".$this->textid[(int)$query].">";
foreach($this->option_select[(int)$query] as $key => $value)
{
$this->template .= "<option id=".$key.">".$value."</option>";
}
$this->tamplate .= "</".$this->type[(int)$query].">";
break;
}//end create input
}
echo $this->template; //return input
}
}
?>
Tag : PHP
|
|
|
|
|
|
Date :
2013-05-30 11:40:28 |
By :
bankza009 |
View :
959 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
จัดไปครับ
|
|
|
|
|
Date :
2013-05-30 12:35:14 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|