-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform.php
118 lines (88 loc) · 2.73 KB
/
form.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
class FormElement
{
private $name, $type,$title, $options, $values,$DBName,$value;
public function FormElement($name, $type,$title,$DBName,$value, $values)
{
$this->name = $name;
$this->type = $type;
$this->values = $values;
$this->title=$title;
$this->DBName=$DBName;
$this->value=$value;
}
public function render($options)
{
$output='';
$this->options=$options;
if ($this->type == 'password' || $this->type == "text") {
$output = '<input type="' . $this->type . '" name="' . $this->name . '" ';
if($this->type!='password')
$output.='value="'.set_value($this->name,$this->value).'" ';
$keys = array_keys($this->options);
foreach ($keys as $key)
$output .= $key . '="' . $this->options[$key] . '" ';
$output .= ' />';
}
if ($this->type=='dropdown')
{
$options='';
$keys = array_keys($this->options);
foreach ($keys as $key)
$options .= $key . '= "' . $this->options[$key] . '" ';
$output = form_dropdown($this->name, $this->values, set_value($this->name,$this->value), $options);
}
return $output;
}
public function getDBName()
{
return $this->DBName;
}
public function getTitle()
{
return $this->title;
}
}
class Form
{
private $elements,$CI,$edit,$temp;
public function Form($edit=false)
{
$this->CI=& get_instance();
$this->edit=$edit;
}
public function addElement($name,$type,$title,$rules,$DBName='',$value='',$values=array())
{
$this->elements[$name]=new FormElement($name,$type,$title,$DBName,$value,$values);
$this->CI->form_validation->set_rules($name, $title, $rules);
}
public function render($name,$options=array())
{
//print_r($this->elements[$name]);
$eln=$this->elements[$name]->render($options);
$output = str_replace('{label-title}',$this->elements[$name]->getTitle(),$this->temp);
$output = str_replace('{input-place}',$eln,$output);
return $output;
}
public function getDBData()
{
$keys = array_keys($this->elements);
foreach ($keys as $key)
if($this->elements[$key]->getDBName()!='')
$arr[$key]=$this->CI->input->post($key);
return $arr;
}
public function setTemp($temp)
{
$this->temp=$temp;
}
public function printAll()
{
$output='';
$keys = array_keys($this->elements);
foreach ($keys as $key)
$output.=$this->render($key);
return $output;
}
}
?>