Trim bloat from Form class.
This commit is contained in:
parent
fa0e6c8db1
commit
77c23c4665
|
@ -21,11 +21,8 @@ public static function open($action = null, $method = 'POST', $attributes = arra
|
||||||
{
|
{
|
||||||
$attributes['action'] = HTML::entities(URL::to((is_null($action)) ? Request::uri() : $action));
|
$attributes['action'] = HTML::entities(URL::to((is_null($action)) ? Request::uri() : $action));
|
||||||
|
|
||||||
// -------------------------------------------------------
|
// If the request method is PUT or DELETE, we'll default the request method to POST
|
||||||
// If the request method is PUT or DELETE, we'll default
|
// since the request method is being spoofed by the form.
|
||||||
// the request method to POST since the reqeust method
|
|
||||||
// is being spoofed by the form.
|
|
||||||
// -------------------------------------------------------
|
|
||||||
$attributes['method'] = ($method == 'PUT' or $method == 'DELETE') ? 'POST' : $method;
|
$attributes['method'] = ($method == 'PUT' or $method == 'DELETE') ? 'POST' : $method;
|
||||||
|
|
||||||
if ( ! array_key_exists('accept-charset', $attributes))
|
if ( ! array_key_exists('accept-charset', $attributes))
|
||||||
|
@ -35,12 +32,8 @@ public static function open($action = null, $method = 'POST', $attributes = arra
|
||||||
|
|
||||||
$html = '<form'.HTML::attributes($attributes).'>';
|
$html = '<form'.HTML::attributes($attributes).'>';
|
||||||
|
|
||||||
// -------------------------------------------------------
|
// If the request method is PUT or DELETE, create a hidden input element with the
|
||||||
// If the method is PUT or DELETE, we'll need to spoof it
|
// request method in it since HTML forms do not support these two methods.
|
||||||
// using a hidden input field.
|
|
||||||
//
|
|
||||||
// For more information, see the Input library.
|
|
||||||
// -------------------------------------------------------
|
|
||||||
if ($method == 'PUT' or $method == 'DELETE')
|
if ($method == 'PUT' or $method == 'DELETE')
|
||||||
{
|
{
|
||||||
$html .= PHP_EOL.static::input('hidden', 'REQUEST_METHOD', $method);
|
$html .= PHP_EOL.static::input('hidden', 'REQUEST_METHOD', $method);
|
||||||
|
@ -81,10 +74,6 @@ public static function token()
|
||||||
*/
|
*/
|
||||||
public static function raw_token()
|
public static function raw_token()
|
||||||
{
|
{
|
||||||
// -------------------------------------------------------
|
|
||||||
// CSRF tokens are stored in the session, so we need to
|
|
||||||
// make sure a driver has been specified.
|
|
||||||
// -------------------------------------------------------
|
|
||||||
if (Config::get('session.driver') == '')
|
if (Config::get('session.driver') == '')
|
||||||
{
|
{
|
||||||
throw new \Exception('Sessions must be enabled to retrieve a CSRF token.');
|
throw new \Exception('Sessions must be enabled to retrieve a CSRF token.');
|
||||||
|
@ -133,6 +122,19 @@ public static function password($name, $attributes = array())
|
||||||
return static::input('password', $name, null, $attributes);
|
return static::input('password', $name, null, $attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a HTML search input element.
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @param string $value
|
||||||
|
* @param array $attributes
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function search($name, $value = null, $attributes = array())
|
||||||
|
{
|
||||||
|
return static::input('search', $name, $value, $attributes);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a HTML email input element.
|
* Create a HTML email input element.
|
||||||
*
|
*
|
||||||
|
@ -159,19 +161,6 @@ public static function telephone($name, $value = null, $attributes = array())
|
||||||
return static::input('tel', $name, $value, $attributes);
|
return static::input('tel', $name, $value, $attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a HTML search input element.
|
|
||||||
*
|
|
||||||
* @param string $name
|
|
||||||
* @param string $value
|
|
||||||
* @param array $attributes
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function search($name, $value = null, $attributes = array())
|
|
||||||
{
|
|
||||||
return static::input('search', $name, $value, $attributes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a HTML URL input element.
|
* Create a HTML URL input element.
|
||||||
*
|
*
|
||||||
|
@ -185,32 +174,6 @@ public static function url($name, $value = null, $attributes = array())
|
||||||
return static::input('url', $name, $value, $attributes);
|
return static::input('url', $name, $value, $attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a HTML color input element.
|
|
||||||
*
|
|
||||||
* @param string $name
|
|
||||||
* @param string $value
|
|
||||||
* @param array $attributes
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function color($name, $value = null, $attributes = array())
|
|
||||||
{
|
|
||||||
return static::input('color', $name, $value, $attributes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a HTML date input element.
|
|
||||||
*
|
|
||||||
* @param string $name
|
|
||||||
* @param string $value
|
|
||||||
* @param array $attributes
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function date($name, $value = null, $attributes = array())
|
|
||||||
{
|
|
||||||
return static::input('date', $name, $value, $attributes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a HTML number input element.
|
* Create a HTML number input element.
|
||||||
*
|
*
|
||||||
|
@ -224,19 +187,6 @@ public static function number($name, $value = null, $attributes = array())
|
||||||
return static::input('number', $name, $value, $attributes);
|
return static::input('number', $name, $value, $attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a HTML range input element.
|
|
||||||
*
|
|
||||||
* @param string $name
|
|
||||||
* @param string $value
|
|
||||||
* @param array $attributes
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function range($name, $value = null, $attributes = array())
|
|
||||||
{
|
|
||||||
return static::input('range', $name, $value, $attributes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a HTML file input element.
|
* Create a HTML file input element.
|
||||||
*
|
*
|
||||||
|
@ -396,25 +346,20 @@ public static function button($value, $attributes = array())
|
||||||
/**
|
/**
|
||||||
* Determine the ID attribute for a form element.
|
* Determine the ID attribute for a form element.
|
||||||
*
|
*
|
||||||
|
* An explicitly specified ID in the attributes takes first precedence, then
|
||||||
|
* the label names will be checked for a label matching the element name.
|
||||||
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
private static function id($name, $attributes)
|
private static function id($name, $attributes)
|
||||||
{
|
{
|
||||||
// -------------------------------------------------------
|
|
||||||
// If an ID attribute was already explicitly specified
|
|
||||||
// for the element in its attributes, use that ID.
|
|
||||||
// -------------------------------------------------------
|
|
||||||
if (array_key_exists('id', $attributes))
|
if (array_key_exists('id', $attributes))
|
||||||
{
|
{
|
||||||
return $attributes['id'];
|
return $attributes['id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------
|
|
||||||
// If a label element was created with a value matching
|
|
||||||
// the name of the form element, use the name as the ID.
|
|
||||||
// -------------------------------------------------------
|
|
||||||
if (in_array($name, static::$labels))
|
if (in_array($name, static::$labels))
|
||||||
{
|
{
|
||||||
return $name;
|
return $name;
|
||||||
|
|
Loading…
Reference in New Issue