This repository was archived by the owner on Jul 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathform.php
More file actions
executable file
·196 lines (172 loc) · 5.34 KB
/
Copy pathform.php
File metadata and controls
executable file
·196 lines (172 loc) · 5.34 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?php namespace Bootsparks;
use \HTML;
use \ReflectionClass;
/**
* Form generation geared around Bootstrap (2.0-wip) from Twitter.
*
* @package Bundles
* @subpackage Twitter
* @author Phill Sparks <me@phills.me.uk>
*
* @see http://twitter.github.com/bootstrap/
*/
class Form extends \Laravel\Form {
/**
* Stacked, left-aligned labels over controls
*/
const TYPE_VERTICAL = 'form-vertical';
/**
* Float left, right-aligned labels on same line as controls
*/
const TYPE_HORIZONTAL = 'form-horizontal';
/**
* Left-aligned label and inline-block controls for compact style
*/
const TYPE_INLINE = 'form-inline';
/**
* Extra-rounded text input for a typical search aesthetic
*/
const TYPE_SEARCH = 'form-search';
/**
* Create a HTML form field.
*
* <code>
* echo Form::field('text', 'name', 'Your name', array('Phill'), array('help' => 'Your full name', 'error' => true));
* </code>
*
* @param string $type Any {@link Laravel\Form} method with $name as the first parameter.
* @param string $name The name of the HTML field.
* @param string $label A HTML label for this field.
* @param array $args Additional parameters passed in order to the Form method.
* @param array $opts Additional form field parameters; help, error, warning or success.
* @return string
*/
public static function field($type, $name, $label, array $args = array(), array $opts = array())
{
$opts = array_filter($opts); // remove false, 0, '', null values
// Add error classes to the fieldset if present in the opts
$class = array_intersect(array('error', 'warning', 'success'), array_keys($opts));
$class = trim('control-group '.implode(' ', $class));
// Name is always the first argument passed to form fields
array_unshift($args, $name);
// Build the HTML
$out = '<div class="'.$class.'">';
if ( ! empty($label))
{
$out .= Form::label($name, $label, array('class' => 'control-label'));
}
$out .= '<div class="controls">'.PHP_EOL;
$out .= forward_static_call_array(array('Form', $type), $args);
foreach (array('error', 'warning', 'success') as $key)
{
if ( ! empty($opts[$key]) and is_string($opts[$key]))
{
// @todo this should be 'help-block' for vertical forms
$out .= '<span class="help-block">'. $opts[$key] .'</span>';
}
}
if ( ! empty($opts['help']))
{
$out .= '<p class="help-block">'. $opts['help'] .'</p>';
}
$out .= '</div>'; // div.controls
$out .= '</div>'.PHP_EOL;
return $out;
}
/**
* @param string $label
* @param array $fields
* @param array $opts
* @return string
*/
public static function field_list($label, array $fields = array(), array $opts = array())
{
$opts = array_filter($opts); // remove false, 0, '', null values
// Add error classes to the fieldset if present in the opts
$class = array_intersect(array('error', 'warning', 'success'), array_keys($opts));
$class = trim('control-group '.implode(' ', $class));
// Build the HTML
$out = '<fieldset class="'.$class.'">';
if ( ! empty($label))
{
$out .= Form::label('', $label, array('class' => 'control-label'));
}
$out .= '<div class="controls"><div class="control-list">'.PHP_EOL;
$out .= implode('', $fields);
foreach (array('error', 'warning', 'success') as $key)
{
if ( ! empty($opts[$key]) and is_string($opts[$key]))
{
$out .= '<p class="help-block">'. $opts[$key] .'</p>';
}
}
if ( ! empty($opts['help']))
{
$out .= '<p class="help-block">'. $opts['help'] .'</p>';
}
$out .= '</div></div>'; // div.control-list div.controls
$out .= '</fieldset>';
return $out;
}
/**
* Create a HTML checkbox input element with a label.
*
* <code>
* // Create a labelled checkbox element that is selected by default
* echo Form::checkbox('Remember my details', 'remember', 'yes', true);
* </code>
*
* @see Laravel\Form::checkbox()
* @param string $label
* @param string $name
* @param string $value
* @param bool $checked
* @param array $attributes
* @return string
*/
public static function labelled_checkbox($name, $label, $value = 1, $checked = false, $attributes = array())
{
$args = func_get_args();
array_splice($args, 1, 1); // Remove $label
return '<label class="checkbox">'.forward_static_call_array(array('Form', 'checkbox'), $args).' '.$label.'</label>'.PHP_EOL;
}
/**
* Create a group of form actions (buttons).
*
* @param mixed $buttons String or array of HTML buttons.
* @return string
*/
public static function actions($buttons)
{
$out = '<div class="form-actions">';
$out .= is_array($buttons) ? implode('', $buttons) : $buttons;
$out .= '</div>';
return $out;
}
/**
* Create a HTML submit input element.
*
* @param string $value
* @param array $attributes
* @return string
*/
public static function submit($value = null, $attributes = array())
{
$attributes['type'] = 'submit';
$attributes['class'] = array_key_exists('class', $attributes) ? $attributes['class'] . ' btn' : 'btn';
return static::button($value, $attributes);
}
/**
* Create a HTML reset input element.
*
* @param string $value
* @param array $attributes
* @return string
*/
public static function reset($value = null, $attributes = array())
{
$attributes['type'] = 'reset';
$attributes['class'] .= ' btn';
return static::button($value, $attributes);
}
}