|
|
@@ -49,28 +49,28 @@ class FormBuilder {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected $labels = array();
|
|
|
|
protected $labels = [];
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* The reserved form open attributes.
|
|
|
|
* The reserved form open attributes.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected $reserved = array('method', 'url', 'route', 'action', 'files');
|
|
|
|
protected $reserved = ['method', 'url', 'route', 'action', 'files'];
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* The form methods that should be spoofed, in uppercase.
|
|
|
|
* The form methods that should be spoofed, in uppercase.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected $spoofedMethods = array('DELETE', 'PATCH', 'PUT');
|
|
|
|
protected $spoofedMethods = ['DELETE', 'PATCH', 'PUT'];
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* The types of inputs to not fill values on by default.
|
|
|
|
* The types of inputs to not fill values on by default.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected $skipValueTypes = array('file', 'password', 'checkbox', 'radio');
|
|
|
|
protected $skipValueTypes = ['file', 'password', 'checkbox', 'radio'];
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Create a new form builder instance.
|
|
|
|
* Create a new form builder instance.
|
|
|
@@ -78,6 +78,7 @@ class FormBuilder {
|
|
|
|
* @param \Illuminate\Routing\UrlGenerator $url
|
|
|
|
* @param \Illuminate\Routing\UrlGenerator $url
|
|
|
|
* @param \Collective\Html\HtmlBuilder $html
|
|
|
|
* @param \Collective\Html\HtmlBuilder $html
|
|
|
|
* @param string $csrfToken
|
|
|
|
* @param string $csrfToken
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function __construct(HtmlBuilder $html, UrlGenerator $url, $csrfToken)
|
|
|
|
public function __construct(HtmlBuilder $html, UrlGenerator $url, $csrfToken)
|
|
|
@@ -91,9 +92,10 @@ class FormBuilder {
|
|
|
|
* Open up a new HTML form.
|
|
|
|
* Open up a new HTML form.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param array $options
|
|
|
|
* @param array $options
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function open(array $options = array())
|
|
|
|
public function open(array $options = [])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$method = array_get($options, 'method', 'post');
|
|
|
|
$method = array_get($options, 'method', 'post');
|
|
|
|
|
|
|
|
|
|
|
@@ -138,9 +140,10 @@ class FormBuilder {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param mixed $model
|
|
|
|
* @param mixed $model
|
|
|
|
* @param array $options
|
|
|
|
* @param array $options
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function model($model, array $options = array())
|
|
|
|
public function model($model, array $options = [])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$this->model = $model;
|
|
|
|
$this->model = $model;
|
|
|
|
|
|
|
|
|
|
|
@@ -151,6 +154,7 @@ class FormBuilder {
|
|
|
|
* Set the model instance on the form builder.
|
|
|
|
* Set the model instance on the form builder.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param mixed $model
|
|
|
|
* @param mixed $model
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function setModel($model)
|
|
|
|
public function setModel($model)
|
|
|
@@ -165,7 +169,7 @@ class FormBuilder {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function close()
|
|
|
|
public function close()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$this->labels = array();
|
|
|
|
$this->labels = [];
|
|
|
|
|
|
|
|
|
|
|
|
$this->model = null;
|
|
|
|
$this->model = null;
|
|
|
|
|
|
|
|
|
|
|
@@ -190,9 +194,10 @@ class FormBuilder {
|
|
|
|
* @param string $name
|
|
|
|
* @param string $name
|
|
|
|
* @param string $value
|
|
|
|
* @param string $value
|
|
|
|
* @param array $options
|
|
|
|
* @param array $options
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function label($name, $value = null, $options = array())
|
|
|
|
public function label($name, $value = null, $options = [])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$this->labels[] = $name;
|
|
|
|
$this->labels[] = $name;
|
|
|
|
|
|
|
|
|
|
|
@@ -208,6 +213,7 @@ class FormBuilder {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @param string $name
|
|
|
|
* @param string|null $value
|
|
|
|
* @param string|null $value
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected function formatLabel($name, $value)
|
|
|
|
protected function formatLabel($name, $value)
|
|
|
@@ -222,9 +228,10 @@ class FormBuilder {
|
|
|
|
* @param string $name
|
|
|
|
* @param string $name
|
|
|
|
* @param string $value
|
|
|
|
* @param string $value
|
|
|
|
* @param array $options
|
|
|
|
* @param array $options
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function input($type, $name, $value = null, $options = array())
|
|
|
|
public function input($type, $name, $value = null, $options = [])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if( ! isset($options['name'])) $options['name'] = $name;
|
|
|
|
if( ! isset($options['name'])) $options['name'] = $name;
|
|
|
|
|
|
|
|
|
|
|
@@ -254,9 +261,10 @@ class FormBuilder {
|
|
|
|
* @param string $name
|
|
|
|
* @param string $name
|
|
|
|
* @param string $value
|
|
|
|
* @param string $value
|
|
|
|
* @param array $options
|
|
|
|
* @param array $options
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function text($name, $value = null, $options = array())
|
|
|
|
public function text($name, $value = null, $options = [])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return $this->input('text', $name, $value, $options);
|
|
|
|
return $this->input('text', $name, $value, $options);
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -266,9 +274,10 @@ class FormBuilder {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @param string $name
|
|
|
|
* @param array $options
|
|
|
|
* @param array $options
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function password($name, $options = array())
|
|
|
|
public function password($name, $options = [])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return $this->input('password', $name, '', $options);
|
|
|
|
return $this->input('password', $name, '', $options);
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -279,9 +288,10 @@ class FormBuilder {
|
|
|
|
* @param string $name
|
|
|
|
* @param string $name
|
|
|
|
* @param string $value
|
|
|
|
* @param string $value
|
|
|
|
* @param array $options
|
|
|
|
* @param array $options
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function hidden($name, $value = null, $options = array())
|
|
|
|
public function hidden($name, $value = null, $options = [])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return $this->input('hidden', $name, $value, $options);
|
|
|
|
return $this->input('hidden', $name, $value, $options);
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -292,22 +302,38 @@ class FormBuilder {
|
|
|
|
* @param string $name
|
|
|
|
* @param string $name
|
|
|
|
* @param string $value
|
|
|
|
* @param string $value
|
|
|
|
* @param array $options
|
|
|
|
* @param array $options
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function email($name, $value = null, $options = array())
|
|
|
|
public function email($name, $value = null, $options = [])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return $this->input('email', $name, $value, $options);
|
|
|
|
return $this->input('email', $name, $value, $options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Create a tel input field.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param string $name
|
|
|
|
|
|
|
|
* @param string $value
|
|
|
|
|
|
|
|
* @param array $options
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return string
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function tel($name, $value = null, $options = [])
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return $this->input('tel', $name, $value, $options);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Create a number input field.
|
|
|
|
* Create a number input field.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @param string $name
|
|
|
|
* @param string $value
|
|
|
|
* @param string $value
|
|
|
|
* @param array $options
|
|
|
|
* @param array $options
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function number($name, $value = null, $options = array())
|
|
|
|
public function number($name, $value = null, $options = [])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return $this->input('number', $name, $value, $options);
|
|
|
|
return $this->input('number', $name, $value, $options);
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -318,9 +344,10 @@ class FormBuilder {
|
|
|
|
* @param string $name
|
|
|
|
* @param string $name
|
|
|
|
* @param string $value
|
|
|
|
* @param string $value
|
|
|
|
* @param array $options
|
|
|
|
* @param array $options
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function date($name, $value = null, $options = array())
|
|
|
|
public function date($name, $value = null, $options = [])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if($value instanceof DateTime)
|
|
|
|
if($value instanceof DateTime)
|
|
|
|
{
|
|
|
|
{
|
|
|
@@ -330,15 +357,30 @@ class FormBuilder {
|
|
|
|
return $this->input('date', $name, $value, $options);
|
|
|
|
return $this->input('date', $name, $value, $options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Create a time input field.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param string $name
|
|
|
|
|
|
|
|
* @param string $value
|
|
|
|
|
|
|
|
* @param array $options
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return string
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function time($name, $value = null, $options = [])
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return $this->input('time', $name, $value, $options);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Create a url input field.
|
|
|
|
* Create a url input field.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @param string $name
|
|
|
|
* @param string $value
|
|
|
|
* @param string $value
|
|
|
|
* @param array $options
|
|
|
|
* @param array $options
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function url($name, $value = null, $options = array())
|
|
|
|
public function url($name, $value = null, $options = [])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return $this->input('url', $name, $value, $options);
|
|
|
|
return $this->input('url', $name, $value, $options);
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -348,9 +390,10 @@ class FormBuilder {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @param string $name
|
|
|
|
* @param array $options
|
|
|
|
* @param array $options
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function file($name, $options = array())
|
|
|
|
public function file($name, $options = [])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return $this->input('file', $name, null, $options);
|
|
|
|
return $this->input('file', $name, null, $options);
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -361,9 +404,10 @@ class FormBuilder {
|
|
|
|
* @param string $name
|
|
|
|
* @param string $name
|
|
|
|
* @param string $value
|
|
|
|
* @param string $value
|
|
|
|
* @param array $options
|
|
|
|
* @param array $options
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function textarea($name, $value = null, $options = array())
|
|
|
|
public function textarea($name, $value = null, $options = [])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if( ! isset($options['name'])) $options['name'] = $name;
|
|
|
|
if( ! isset($options['name'])) $options['name'] = $name;
|
|
|
|
|
|
|
|
|
|
|
@@ -390,6 +434,7 @@ class FormBuilder {
|
|
|
|
* Set the text area size on the attributes.
|
|
|
|
* Set the text area size on the attributes.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param array $options
|
|
|
|
* @param array $options
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected function setTextAreaSize($options)
|
|
|
|
protected function setTextAreaSize($options)
|
|
|
@@ -413,13 +458,14 @@ class FormBuilder {
|
|
|
|
* Set the text area size using the quick "size" attribute.
|
|
|
|
* Set the text area size using the quick "size" attribute.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param array $options
|
|
|
|
* @param array $options
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected function setQuickTextAreaSize($options)
|
|
|
|
protected function setQuickTextAreaSize($options)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$segments = explode('x', $options['size']);
|
|
|
|
$segments = explode('x', $options['size']);
|
|
|
|
|
|
|
|
|
|
|
|
return array_merge($options, array('cols' => $segments[0], 'rows' => $segments[1]));
|
|
|
|
return array_merge($options, ['cols' => $segments[0], 'rows' => $segments[1]]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@@ -429,9 +475,10 @@ class FormBuilder {
|
|
|
|
* @param array $list
|
|
|
|
* @param array $list
|
|
|
|
* @param string $selected
|
|
|
|
* @param string $selected
|
|
|
|
* @param array $options
|
|
|
|
* @param array $options
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function select($name, $list = array(), $selected = null, $options = array())
|
|
|
|
public function select($name, $list = [], $selected = null, $options = [])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// When building a select box the "value" attribute is really the selected one
|
|
|
|
// When building a select box the "value" attribute is really the selected one
|
|
|
|
// so we will use that when checking the model or session for a value which
|
|
|
|
// so we will use that when checking the model or session for a value which
|
|
|
@@ -445,7 +492,13 @@ class FormBuilder {
|
|
|
|
// We will simply loop through the options and build an HTML value for each of
|
|
|
|
// We will simply loop through the options and build an HTML value for each of
|
|
|
|
// them until we have an array of HTML declarations. Then we will join them
|
|
|
|
// them until we have an array of HTML declarations. Then we will join them
|
|
|
|
// all together into one single HTML element that can be put on the form.
|
|
|
|
// all together into one single HTML element that can be put on the form.
|
|
|
|
$html = array();
|
|
|
|
$html = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(isset($options['placeholder']))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$html[] = $this->placeholderOption($options['placeholder'], $selected);
|
|
|
|
|
|
|
|
unset($options['placeholder']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach($list as $value => $display)
|
|
|
|
foreach($list as $value => $display)
|
|
|
|
{
|
|
|
|
{
|
|
|
@@ -470,9 +523,10 @@ class FormBuilder {
|
|
|
|
* @param string $end
|
|
|
|
* @param string $end
|
|
|
|
* @param string $selected
|
|
|
|
* @param string $selected
|
|
|
|
* @param array $options
|
|
|
|
* @param array $options
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function selectRange($name, $begin, $end, $selected = null, $options = array())
|
|
|
|
public function selectRange($name, $begin, $end, $selected = null, $options = [])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$range = array_combine($range = range($begin, $end), $range);
|
|
|
|
$range = array_combine($range = range($begin, $end), $range);
|
|
|
|
|
|
|
|
|
|
|
@@ -487,11 +541,12 @@ class FormBuilder {
|
|
|
|
* @param string $end
|
|
|
|
* @param string $end
|
|
|
|
* @param string $selected
|
|
|
|
* @param string $selected
|
|
|
|
* @param array $options
|
|
|
|
* @param array $options
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function selectYear()
|
|
|
|
public function selectYear()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return call_user_func_array(array($this, 'selectRange'), func_get_args());
|
|
|
|
return call_user_func_array([$this, 'selectRange'], func_get_args());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@@ -501,11 +556,12 @@ class FormBuilder {
|
|
|
|
* @param string $selected
|
|
|
|
* @param string $selected
|
|
|
|
* @param array $options
|
|
|
|
* @param array $options
|
|
|
|
* @param string $format
|
|
|
|
* @param string $format
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function selectMonth($name, $selected = null, $options = array(), $format = '%B')
|
|
|
|
public function selectMonth($name, $selected = null, $options = [], $format = '%B')
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$months = array();
|
|
|
|
$months = [];
|
|
|
|
|
|
|
|
|
|
|
|
foreach(range(1, 12) as $month)
|
|
|
|
foreach(range(1, 12) as $month)
|
|
|
|
{
|
|
|
|
{
|
|
|
@@ -521,6 +577,7 @@ class FormBuilder {
|
|
|
|
* @param string $display
|
|
|
|
* @param string $display
|
|
|
|
* @param string $value
|
|
|
|
* @param string $value
|
|
|
|
* @param string $selected
|
|
|
|
* @param string $selected
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function getSelectOption($display, $value, $selected)
|
|
|
|
public function getSelectOption($display, $value, $selected)
|
|
|
@@ -539,11 +596,12 @@ class FormBuilder {
|
|
|
|
* @param array $list
|
|
|
|
* @param array $list
|
|
|
|
* @param string $label
|
|
|
|
* @param string $label
|
|
|
|
* @param string $selected
|
|
|
|
* @param string $selected
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected function optionGroup($list, $label, $selected)
|
|
|
|
protected function optionGroup($list, $label, $selected)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$html = array();
|
|
|
|
$html = [];
|
|
|
|
|
|
|
|
|
|
|
|
foreach($list as $value => $display)
|
|
|
|
foreach($list as $value => $display)
|
|
|
|
{
|
|
|
|
{
|
|
|
@@ -559,13 +617,32 @@ class FormBuilder {
|
|
|
|
* @param string $display
|
|
|
|
* @param string $display
|
|
|
|
* @param string $value
|
|
|
|
* @param string $value
|
|
|
|
* @param string $selected
|
|
|
|
* @param string $selected
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected function option($display, $value, $selected)
|
|
|
|
protected function option($display, $value, $selected)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$selected = $this->getSelectedValue($value, $selected);
|
|
|
|
$selected = $this->getSelectedValue($value, $selected);
|
|
|
|
|
|
|
|
|
|
|
|
$options = array('value' => e($value), 'selected' => $selected);
|
|
|
|
$options = ['value' => e($value), 'selected' => $selected];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return '<option' . $this->html->attributes($options) . '>' . e($display) . '</option>';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Create a placeholder select element option.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param $display
|
|
|
|
|
|
|
|
* @param $selected
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return string
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
protected function placeholderOption($display, $selected)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$selected = $this->getSelectedValue(null, $selected);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$options = compact('selected');
|
|
|
|
|
|
|
|
$options['value'] = '';
|
|
|
|
|
|
|
|
|
|
|
|
return '<option' . $this->html->attributes($options) . '>' . e($display) . '</option>';
|
|
|
|
return '<option' . $this->html->attributes($options) . '>' . e($display) . '</option>';
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -575,6 +652,7 @@ class FormBuilder {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param string $value
|
|
|
|
* @param string $value
|
|
|
|
* @param string $selected
|
|
|
|
* @param string $selected
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string|null
|
|
|
|
* @return string|null
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected function getSelectedValue($value, $selected)
|
|
|
|
protected function getSelectedValue($value, $selected)
|
|
|
@@ -594,9 +672,10 @@ class FormBuilder {
|
|
|
|
* @param mixed $value
|
|
|
|
* @param mixed $value
|
|
|
|
* @param bool $checked
|
|
|
|
* @param bool $checked
|
|
|
|
* @param array $options
|
|
|
|
* @param array $options
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function checkbox($name, $value = 1, $checked = null, $options = array())
|
|
|
|
public function checkbox($name, $value = 1, $checked = null, $options = [])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return $this->checkable('checkbox', $name, $value, $checked, $options);
|
|
|
|
return $this->checkable('checkbox', $name, $value, $checked, $options);
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -608,9 +687,10 @@ class FormBuilder {
|
|
|
|
* @param mixed $value
|
|
|
|
* @param mixed $value
|
|
|
|
* @param bool $checked
|
|
|
|
* @param bool $checked
|
|
|
|
* @param array $options
|
|
|
|
* @param array $options
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function radio($name, $value = null, $checked = null, $options = array())
|
|
|
|
public function radio($name, $value = null, $checked = null, $options = [])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(is_null($value)) $value = $name;
|
|
|
|
if(is_null($value)) $value = $name;
|
|
|
|
|
|
|
|
|
|
|
@@ -625,6 +705,7 @@ class FormBuilder {
|
|
|
|
* @param mixed $value
|
|
|
|
* @param mixed $value
|
|
|
|
* @param bool $checked
|
|
|
|
* @param bool $checked
|
|
|
|
* @param array $options
|
|
|
|
* @param array $options
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected function checkable($type, $name, $value, $checked, $options)
|
|
|
|
protected function checkable($type, $name, $value, $checked, $options)
|
|
|
@@ -643,6 +724,7 @@ class FormBuilder {
|
|
|
|
* @param string $name
|
|
|
|
* @param string $name
|
|
|
|
* @param mixed $value
|
|
|
|
* @param mixed $value
|
|
|
|
* @param bool $checked
|
|
|
|
* @param bool $checked
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected function getCheckedState($type, $name, $value, $checked)
|
|
|
|
protected function getCheckedState($type, $name, $value, $checked)
|
|
|
@@ -666,6 +748,7 @@ class FormBuilder {
|
|
|
|
* @param string $name
|
|
|
|
* @param string $name
|
|
|
|
* @param mixed $value
|
|
|
|
* @param mixed $value
|
|
|
|
* @param bool $checked
|
|
|
|
* @param bool $checked
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected function getCheckboxCheckedState($name, $value, $checked)
|
|
|
|
protected function getCheckboxCheckedState($name, $value, $checked)
|
|
|
@@ -685,6 +768,7 @@ class FormBuilder {
|
|
|
|
* @param string $name
|
|
|
|
* @param string $name
|
|
|
|
* @param mixed $value
|
|
|
|
* @param mixed $value
|
|
|
|
* @param bool $checked
|
|
|
|
* @param bool $checked
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected function getRadioCheckedState($name, $value, $checked)
|
|
|
|
protected function getRadioCheckedState($name, $value, $checked)
|
|
|
@@ -698,6 +782,7 @@ class FormBuilder {
|
|
|
|
* Determine if old input or model input exists for a key.
|
|
|
|
* Determine if old input or model input exists for a key.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @param string $name
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected function missingOldAndModel($name)
|
|
|
|
protected function missingOldAndModel($name)
|
|
|
@@ -710,9 +795,10 @@ class FormBuilder {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param string $value
|
|
|
|
* @param string $value
|
|
|
|
* @param array $attributes
|
|
|
|
* @param array $attributes
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function reset($value, $attributes = array())
|
|
|
|
public function reset($value, $attributes = [])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return $this->input('reset', null, $value, $attributes);
|
|
|
|
return $this->input('reset', null, $value, $attributes);
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -723,9 +809,10 @@ class FormBuilder {
|
|
|
|
* @param string $url
|
|
|
|
* @param string $url
|
|
|
|
* @param string $name
|
|
|
|
* @param string $name
|
|
|
|
* @param array $attributes
|
|
|
|
* @param array $attributes
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function image($url, $name = null, $attributes = array())
|
|
|
|
public function image($url, $name = null, $attributes = [])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$attributes['src'] = $this->url->asset($url);
|
|
|
|
$attributes['src'] = $this->url->asset($url);
|
|
|
|
|
|
|
|
|
|
|
@@ -737,9 +824,10 @@ class FormBuilder {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param string $value
|
|
|
|
* @param string $value
|
|
|
|
* @param array $options
|
|
|
|
* @param array $options
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function submit($value = null, $options = array())
|
|
|
|
public function submit($value = null, $options = [])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return $this->input('submit', null, $value, $options);
|
|
|
|
return $this->input('submit', null, $value, $options);
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -749,9 +837,10 @@ class FormBuilder {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param string $value
|
|
|
|
* @param string $value
|
|
|
|
* @param array $options
|
|
|
|
* @param array $options
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function button($value = null, $options = array())
|
|
|
|
public function button($value = null, $options = [])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if( ! array_key_exists('type', $options))
|
|
|
|
if( ! array_key_exists('type', $options))
|
|
|
|
{
|
|
|
|
{
|
|
|
@@ -765,6 +854,7 @@ class FormBuilder {
|
|
|
|
* Parse the form action method.
|
|
|
|
* Parse the form action method.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param string $method
|
|
|
|
* @param string $method
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected function getMethod($method)
|
|
|
|
protected function getMethod($method)
|
|
|
@@ -778,6 +868,7 @@ class FormBuilder {
|
|
|
|
* Get the form action from the options.
|
|
|
|
* Get the form action from the options.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param array $options
|
|
|
|
* @param array $options
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected function getAction(array $options)
|
|
|
|
protected function getAction(array $options)
|
|
|
@@ -810,6 +901,7 @@ class FormBuilder {
|
|
|
|
* Get the action for a "url" option.
|
|
|
|
* Get the action for a "url" option.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param array|string $options
|
|
|
|
* @param array|string $options
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected function getUrlAction($options)
|
|
|
|
protected function getUrlAction($options)
|
|
|
@@ -826,6 +918,7 @@ class FormBuilder {
|
|
|
|
* Get the action for a "route" option.
|
|
|
|
* Get the action for a "route" option.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param array|string $options
|
|
|
|
* @param array|string $options
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected function getRouteAction($options)
|
|
|
|
protected function getRouteAction($options)
|
|
|
@@ -842,6 +935,7 @@ class FormBuilder {
|
|
|
|
* Get the action for an "action" option.
|
|
|
|
* Get the action for an "action" option.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param array|string $options
|
|
|
|
* @param array|string $options
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected function getControllerAction($options)
|
|
|
|
protected function getControllerAction($options)
|
|
|
@@ -858,11 +952,12 @@ class FormBuilder {
|
|
|
|
* Get the form appendage for the given method.
|
|
|
|
* Get the form appendage for the given method.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param string $method
|
|
|
|
* @param string $method
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected function getAppendage($method)
|
|
|
|
protected function getAppendage($method)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
list($method, $appendage) = array(strtoupper($method), '');
|
|
|
|
list($method, $appendage) = [strtoupper($method), ''];
|
|
|
|
|
|
|
|
|
|
|
|
// If the HTTP method is in this list of spoofed methods, we will attach the
|
|
|
|
// If the HTTP method is in this list of spoofed methods, we will attach the
|
|
|
|
// method spoofer hidden input to the form. This allows us to use regular
|
|
|
|
// method spoofer hidden input to the form. This allows us to use regular
|
|
|
@@ -888,6 +983,7 @@ class FormBuilder {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @param string $name
|
|
|
|
* @param array $attributes
|
|
|
|
* @param array $attributes
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function getIdAttribute($name, $attributes)
|
|
|
|
public function getIdAttribute($name, $attributes)
|
|
|
@@ -908,6 +1004,7 @@ class FormBuilder {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @param string $name
|
|
|
|
* @param string $value
|
|
|
|
* @param string $value
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function getValueAttribute($name, $value = null)
|
|
|
|
public function getValueAttribute($name, $value = null)
|
|
|
@@ -931,6 +1028,7 @@ class FormBuilder {
|
|
|
|
* Get the model value that should be assigned to the field.
|
|
|
|
* Get the model value that should be assigned to the field.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @param string $name
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected function getModelValueAttribute($name)
|
|
|
|
protected function getModelValueAttribute($name)
|
|
|
@@ -942,6 +1040,7 @@ class FormBuilder {
|
|
|
|
* Get a value from the session's old input.
|
|
|
|
* Get a value from the session's old input.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @param string $name
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function old($name)
|
|
|
|
public function old($name)
|
|
|
@@ -966,11 +1065,12 @@ class FormBuilder {
|
|
|
|
* Transform key from array to dot syntax.
|
|
|
|
* Transform key from array to dot syntax.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param string $key
|
|
|
|
* @param string $key
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected function transformKey($key)
|
|
|
|
protected function transformKey($key)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return str_replace(array('.', '[]', '[', ']'), array('_', '', '.', ''), $key);
|
|
|
|
return str_replace(['.', '[]', '[', ']'], ['_', '', '.', ''], $key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@@ -987,6 +1087,7 @@ class FormBuilder {
|
|
|
|
* Set the session store implementation.
|
|
|
|
* Set the session store implementation.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Session\Store $session
|
|
|
|
* @param \Illuminate\Session\Store $session
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function setSessionStore(Session $session)
|
|
|
|
public function setSessionStore(Session $session)
|
|
|
@@ -995,5 +1096,4 @@ class FormBuilder {
|
|
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|