/
formhidden.php
78 lines (60 loc) · 1.75 KB
/
formhidden.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
<?php
/**
* Formhidden Helper: create html hidden tags.
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2009, Yasushi Ichikawa. (http://d.hatena.ne.jp/cakephper/)
* @link http://d.hatena.ne.jp/cakephper/
* @package cakeplus
* @subpackage cakeplus
* @version 0.02
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*
*
* =====Usage=====
* //in controller
* var $helpers = array('Cakeplus.Formhidden');
*
* //in view(ctp file) for using $this->data
* <?php echo $formhidden->hiddenVars(); ?>
*
* //in view(ctp file) for using $data_arr parameter
* <?php echo $formhidden->hiddenVars($data_arr); ?>
*
* ===============
*
*/
class FormhiddenHelper extends Helper {
var $helpers = array('Form');
// String data of Hidden tags.
var $hidden_output = null;
/**
* construct html hidden tag
*
* @param array $data_arr //if not set, using $this->data
* @return String
*/
function hiddenVars( $data_arr = null ) {
if( empty($this->data) && empty($data_arr) ){ return; }
if( !is_array($data_arr) || empty($data_arr) ){
$data_arr = $this->data;
}
$this->_createHidden( $data_arr );
$output = $this->hidden_output;
$this->hidden_output = null;
return $output;
}
function _createHidden( $data, $parent_key = null ){
if( is_array( $data ) ){
foreach( $data as $key => $val ){
$parent_key_arr = ( isset($parent_key) ) ? $parent_key . '.' . $key : $key ;
self::_createHidden( $val, $parent_key_arr );
}
}else{
$this->hidden_output .= $this->Form->hidden( $parent_key )."\n";
}
}
}
?>