-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathform.class.php
More file actions
97 lines (85 loc) · 1.9 KB
/
form.class.php
File metadata and controls
97 lines (85 loc) · 1.9 KB
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
<?php
require_once 'form/input.class.php';
class NyaaForm extends NyaaObject
{
public $inputs = array( );
public $hiddens = array( );
public $name = "";
public $method = "post";
public $enctype = "application/x-www-form-urlencode";
public $headTemplate = '<form name=":name" method=":method" enctype=":enctype">';
public $tailTemplate = '</form>';
function loadFile( $file )
{
$store = NyaaConf::load($file);
foreach( $store->get() as $k=>$v )
{
$v['type'] = isset($v['type']) ? $v['type']: 'text';
$input = NyaaFormInput::factory(array_merge($v, array('name'=>$k)));
$this->addInput( $input );
}
}
function setEnctype( $enctype )
{
$this->enctype = $enctype;
}
function addInput( $object )
{
$index = count($this->inputs);
$this->inputs[$index] = $object;
$this->inputIndex[$object->getProp('name')] = $index;
}
function getInputs( )
{
$ret = array( );
$args = func_get_args( );
if(count($args) == 0)
return $this->inputs;
foreach($args as $k)
$ret[$k] = $this->getInput($k);
return $ret;
}
function getInput( $name )
{
if(!isset($this->inputIndex[$name]))
return false;
$index = $this->inputIndex[$name];
return $this->inputs[$index];
}
function addHidden( $key,$value )
{
$this->hiddens[] = NyaaFormInput::factory(
array(
'type'=>'hidden',
'name'=>$key,
'value'=>$value
)
);
}
function getProp( $name )
{
return $this->$name;
}
function setValues( $values )
{
foreach( $values as $k=>$v )
{
if( $this->getInput($k) )
$this->getInput($k)->setValue( $v );
}
}
function toHead( )
{
$head = preg_replace('/:([a-zA-Z_]+)/e', '$this->getProp("\1")', $this->headTemplate );
foreach( $this->hiddens as $input )
{
$head.= $input->toHtml();
}
return $head;
}
function toTail( )
{
return preg_replace('/:([a-zA-Z_]+)/e', '$this->getProp("\1")', $this->tailTemplate );
}
}
?>