Browse Source

Added Form::open_secure and Form::open_secure_for_files

Taylor Otwell 13 years ago
parent
commit
36d9fe0b87
1 changed files with 32 additions and 4 deletions
  1. 32 4
      system/form.php

+ 32 - 4
system/form.php

@@ -15,11 +15,12 @@ class Form {
 	 * @param  string  $action
 	 * @param  string  $method
 	 * @param  array   $attributes
+	 * @param  bool    $https
 	 * @return string
 	 */	
-	public static function open($action = null, $method = 'POST', $attributes = array())
+	public static function open($action = null, $method = 'POST', $attributes = array(), $https = false)
 	{
-		$attributes['action'] = HTML::entities(URL::to((is_null($action)) ? Request::uri() : $action));
+		$attributes['action'] = HTML::entities(URL::to(((is_null($action)) ? Request::uri() : $action), $https));
 
 		// If the request method is PUT or DELETE, we'll default the request method to POST
 		// since the request method is being spoofed by the form.
@@ -42,19 +43,46 @@ class Form {
 		return $html.PHP_EOL;
 	}
 
+	/**
+	 * Open a HTML form with a HTTPS action.
+	 *
+	 * @param  string  $action
+	 * @param  string  $method
+	 * @param  array   $attributes
+	 * @return string
+	 */
+	public static function open_secure($action = null, $method = 'POST', $attributes = array())
+	{
+		return static::open($action, $method, $attributes, true);
+	}
+
 	/**
 	 * Open a HTML form that accepts file uploads.
 	 *
 	 * @param  string  $action
 	 * @param  string  $method
 	 * @param  array   $attributes
+	 * @param  bool    $https
 	 * @return string
 	 */	
-	public static function open_for_files($action = null, $method = 'POST', $attributes = array())
+	public static function open_for_files($action = null, $method = 'POST', $attributes = array(), $https = false)
 	{
 		$attributes['enctype'] = 'multipart/form-data';
 
-		return static::open($action, $method, $attributes);
+		return static::open($action, $method, $attributes, $https);
+	}
+
+	/**
+	 * Open a HTML form that accepts file uploads with a HTTPS action.
+	 *
+	 * @param  string  $action
+	 * @param  string  $method
+	 * @param  array   $attributes
+	 * @return string
+	 */	
+	public static function open_secure_for_files($action = null, $method = 'POST', $attributes = array())
+	{
+		return static::open_for_files($action, $method, $attributes, true);
 	}
 
 	/**