From e0b89a7a4e7dbd9e551c8c8f617c12ffd19e3f8e Mon Sep 17 00:00:00 2001 From: totoprayogo1916 Date: Thu, 7 Jan 2021 17:54:39 +0700 Subject: [PATCH] reindent & fix some examples --- .../source/helpers/array_helper.rst | 2 +- .../source/helpers/cookie_helper.rst | 82 +- user_guide_src/source/helpers/date_helper.rst | 50 +- .../source/helpers/filesystem_helper.rst | 316 +++--- user_guide_src/source/helpers/form_helper.rst | 910 +++++++++--------- user_guide_src/source/helpers/index.rst | 6 +- .../source/helpers/inflector_helper.rst | 138 +-- .../source/helpers/number_helper.rst | 6 +- .../source/helpers/security_helper.rst | 42 +- user_guide_src/source/helpers/test_helper.rst | 26 +- user_guide_src/source/helpers/text_helper.rst | 520 +++++----- user_guide_src/source/helpers/xml_helper.rst | 38 +- user_guide_src/source/models/entities.rst | 6 +- user_guide_src/source/models/model.rst | 4 +- 14 files changed, 1073 insertions(+), 1073 deletions(-) diff --git a/user_guide_src/source/helpers/array_helper.rst b/user_guide_src/source/helpers/array_helper.rst index 1a9a3c6fd933..5394ab650ab4 100644 --- a/user_guide_src/source/helpers/array_helper.rst +++ b/user_guide_src/source/helpers/array_helper.rst @@ -13,7 +13,7 @@ Loading this Helper This helper is loaded using the following code:: - helper('array'); + helper('array'); Available Functions =================== diff --git a/user_guide_src/source/helpers/cookie_helper.rst b/user_guide_src/source/helpers/cookie_helper.rst index d41896f51c34..0344954cda6d 100755 --- a/user_guide_src/source/helpers/cookie_helper.rst +++ b/user_guide_src/source/helpers/cookie_helper.rst @@ -17,7 +17,7 @@ Loading this Helper This helper is loaded using the following code:: - helper('cookie'); + helper('cookie'); Available Functions =================== @@ -26,54 +26,54 @@ The following functions are available: .. php:function:: set_cookie($name[, $value = ''[, $expire = ''[, $domain = ''[, $path = '/'[, $prefix = ''[, $secure = false[, $httpOnly = false[, $sameSite = '']]]]]]]]) - :param mixed $name: Cookie name *or* associative array of all of the parameters available to this function - :param string $value: Cookie value - :param int $expire: Number of seconds until expiration - :param string $domain: Cookie domain (usually: .yourdomain.com) - :param string $path: Cookie path - :param string $prefix: Cookie name prefix - :param bool $secure: Whether to only send the cookie through HTTPS - :param bool $httpOnly: Whether to hide the cookie from JavaScript - :param string $sameSite: The value for the SameSite cookie parameter. If null, the default from `config/App.php` is used - :rtype: void - - This helper function gives you friendlier syntax to set browser - cookies. Refer to the :doc:`Response Library ` for - a description of its use, as this function is an alias for - ``Response::setCookie()``. + :param mixed $name: Cookie name *or* associative array of all of the parameters available to this function + :param string $value: Cookie value + :param int $expire: Number of seconds until expiration + :param string $domain: Cookie domain (usually: .yourdomain.com) + :param string $path: Cookie path + :param string $prefix: Cookie name prefix + :param bool $secure: Whether to only send the cookie through HTTPS + :param bool $httpOnly: Whether to hide the cookie from JavaScript + :param string $sameSite: The value for the SameSite cookie parameter. If null, the default from `config/App.php` is used + :rtype: void + + This helper function gives you friendlier syntax to set browser + cookies. Refer to the :doc:`Response Library ` for + a description of its use, as this function is an alias for + ``Response::setCookie()``. .. php:function:: get_cookie($index[, $xssClean = false]) - :param string $index: Cookie name - :param bool $xss_clean: Whether to apply XSS filtering to the returned value - :returns: The cookie value or NULL if not found - :rtype: mixed + :param string $index: Cookie name + :param bool $xss_clean: Whether to apply XSS filtering to the returned value + :returns: The cookie value or NULL if not found + :rtype: mixed - This helper function gives you friendlier syntax to get browser - cookies. Refer to the :doc:`IncomingRequest Library ` for - detailed description of its use, as this function acts very - similarly to ``IncomingRequest::getCookie()``, except it will also prepend - the ``$cookiePrefix`` that you might've set in your - *app/Config/App.php* file. + This helper function gives you friendlier syntax to get browser + cookies. Refer to the :doc:`IncomingRequest Library ` for + detailed description of its use, as this function acts very + similarly to ``IncomingRequest::getCookie()``, except it will also prepend + the ``$cookiePrefix`` that you might've set in your + *app/Config/App.php* file. .. php:function:: delete_cookie($name[, $domain = ''[, $path = '/'[, $prefix = '']]]) - :param string $name: Cookie name - :param string $domain: Cookie domain (usually: .yourdomain.com) - :param string $path: Cookie path - :param string $prefix: Cookie name prefix - :rtype: void + :param string $name: Cookie name + :param string $domain: Cookie domain (usually: .yourdomain.com) + :param string $path: Cookie path + :param string $prefix: Cookie name prefix + :rtype: void - Lets you delete a cookie. Unless you've set a custom path or other - values, only the name of the cookie is needed. - :: + Lets you delete a cookie. Unless you've set a custom path or other + values, only the name of the cookie is needed. + :: - delete_cookie('name'); + delete_cookie('name'); - This function is otherwise identical to ``set_cookie()``, except that it - does not have the value and expiration parameters. You can submit an - array of values in the first parameter or you can set discrete - parameters. - :: + This function is otherwise identical to ``set_cookie()``, except that it + does not have the value and expiration parameters. You can submit an + array of values in the first parameter or you can set discrete + parameters. + :: - delete_cookie($name, $domain, $path, $prefix); + delete_cookie($name, $domain, $path, $prefix); diff --git a/user_guide_src/source/helpers/date_helper.rst b/user_guide_src/source/helpers/date_helper.rst index 3a05f5cff8e8..a243888c75c3 100644 --- a/user_guide_src/source/helpers/date_helper.rst +++ b/user_guide_src/source/helpers/date_helper.rst @@ -17,7 +17,7 @@ Loading this Helper This helper is loaded using the following code:: - helper('date'); + helper('date'); Available Functions =================== @@ -26,38 +26,38 @@ The following functions are available: .. php:function:: now([$timezone = NULL]) - :param string $timezone: Timezone - :returns: UNIX timestamp - :rtype: int + :param string $timezone: Timezone + :returns: UNIX timestamp + :rtype: int - Returns the current time as a UNIX timestamp, referenced either to your server's - local time or any PHP supported timezone, based on the "time reference" setting - in your config file. If you do not intend to set your master time reference to - any other PHP supported timezone (which you'll typically do if you run a site - that lets each user set their own timezone settings) there is no benefit to using - this function over PHP's ``time()`` function. - :: + Returns the current time as a UNIX timestamp, referenced either to your server's + local time or any PHP supported timezone, based on the "time reference" setting + in your config file. If you do not intend to set your master time reference to + any other PHP supported timezone (which you'll typically do if you run a site + that lets each user set their own timezone settings) there is no benefit to using + this function over PHP's ``time()`` function. + :: - echo now('Australia/Victoria'); + echo now('Australia/Victoria'); - If a timezone is not provided, it will return ``time()`` based on the - **time_reference** setting. + If a timezone is not provided, it will return ``time()`` based on the + **time_reference** setting. .. php:function:: timezone_select([$class = '', $default = '', $what = \DateTimeZone::ALL, $country = null]) - :param string $class: Optional class to apply to the select field - :param string $default: Default value for initial selection - :param int $what: DateTimeZone class constants (see `listIdentifiers `_) - :param string $country: A two-letter ISO 3166-1 compatible country code (see `listIdentifiers `_) - :returns: Preformatted HTML select field - :rtype: string + :param string $class: Optional class to apply to the select field + :param string $default: Default value for initial selection + :param int $what: DateTimeZone class constants (see `listIdentifiers `_) + :param string $country: A two-letter ISO 3166-1 compatible country code (see `listIdentifiers `_) + :returns: Preformatted HTML select field + :rtype: string - Generates a `select` form field of available timezones (optionally filtered by `$what` and `$country`). - You can supply an option class to apply to the field to make formatting easier, as well as a default - selected value. - :: + Generates a `select` form field of available timezones (optionally filtered by `$what` and `$country`). + You can supply an option class to apply to the field to make formatting easier, as well as a default + selected value. + :: - echo timezone_select('custom-select', 'America/New_York'); + echo timezone_select('custom-select', 'America/New_York'); Many functions previously found in the CodeIgniter 3 ``date_helper`` have been moved to the ``I18n`` module in CodeIgniter 4. diff --git a/user_guide_src/source/helpers/filesystem_helper.rst b/user_guide_src/source/helpers/filesystem_helper.rst index f6dfb23242b7..2b099d292940 100644 --- a/user_guide_src/source/helpers/filesystem_helper.rst +++ b/user_guide_src/source/helpers/filesystem_helper.rst @@ -19,7 +19,7 @@ This helper is loaded using the following code: :: - helper('filesystem'); + helper('filesystem'); Available Functions =================== @@ -28,220 +28,220 @@ The following functions are available: .. php:function:: directory_map($source_dir[, $directory_depth = 0[, $hidden = FALSE]]) - :param string $source_dir: Path to the source directory - :param int $directory_depth: Depth of directories to traverse (0 = fully recursive, 1 = current dir, etc) - :param bool $hidden: Whether to include hidden directories - :returns: An array of files - :rtype: array - - Examples:: - - $map = directory_map('./mydirectory/'); - - .. note:: Paths are almost always relative to your main index.php file. - - Sub-folders contained within the directory will be mapped as well. If - you wish to control the recursion depth, you can do so using the second - parameter (integer). A depth of 1 will only map the top level directory:: - - $map = directory_map('./mydirectory/', 1); - - By default, hidden files will not be included in the returned array. To - override this behavior, you may set a third parameter to true (boolean):: - - $map = directory_map('./mydirectory/', FALSE, TRUE); - - Each folder name will be an array index, while its contained files will - be numerically indexed. Here is an example of a typical array:: - - Array ( - [libraries] => Array - ( - [0] => benchmark.html - [1] => config.html - ["database/"] => Array - ( - [0] => query_builder.html - [1] => binds.html - [2] => configuration.html - [3] => connecting.html - [4] => examples.html - [5] => fields.html - [6] => index.html - [7] => queries.html - ) - [2] => email.html - [3] => file_uploading.html - [4] => image_lib.html - [5] => input.html - [6] => language.html - [7] => loader.html - [8] => pagination.html - [9] => uri.html - ) - - If no results are found, this will return an empty array. + :param string $source_dir: Path to the source directory + :param int $directory_depth: Depth of directories to traverse (0 = fully recursive, 1 = current dir, etc) + :param bool $hidden: Whether to include hidden directories + :returns: An array of files + :rtype: array + + Examples:: + + $map = directory_map('./mydirectory/'); + + .. note:: Paths are almost always relative to your main index.php file. + + Sub-folders contained within the directory will be mapped as well. If + you wish to control the recursion depth, you can do so using the second + parameter (integer). A depth of 1 will only map the top level directory:: + + $map = directory_map('./mydirectory/', 1); + + By default, hidden files will not be included in the returned array. To + override this behavior, you may set a third parameter to true (boolean):: + + $map = directory_map('./mydirectory/', FALSE, TRUE); + + Each folder name will be an array index, while its contained files will + be numerically indexed. Here is an example of a typical array:: + + Array ( + [libraries] => Array + ( + [0] => benchmark.html + [1] => config.html + ["database/"] => Array + ( + [0] => query_builder.html + [1] => binds.html + [2] => configuration.html + [3] => connecting.html + [4] => examples.html + [5] => fields.html + [6] => index.html + [7] => queries.html + ) + [2] => email.html + [3] => file_uploading.html + [4] => image_lib.html + [5] => input.html + [6] => language.html + [7] => loader.html + [8] => pagination.html + [9] => uri.html + ) + + If no results are found, this will return an empty array. .. php:function:: write_file($path, $data[, $mode = 'wb']) - :param string $path: File path - :param string $data: Data to write to file - :param string $mode: ``fopen()`` mode - :returns: TRUE if the write was successful, FALSE in case of an error - :rtype: bool + :param string $path: File path + :param string $data: Data to write to file + :param string $mode: ``fopen()`` mode + :returns: TRUE if the write was successful, FALSE in case of an error + :rtype: bool - Writes data to the file specified in the path. If the file does not exist then the - function will create it. + Writes data to the file specified in the path. If the file does not exist then the + function will create it. - Example:: + Example:: - $data = 'Some file data'; - if ( ! write_file('./path/to/file.php', $data)) - {      - echo 'Unable to write the file'; - } - else - {      - echo 'File written!'; - } + $data = 'Some file data'; + if ( ! write_file('./path/to/file.php', $data)) + {      + echo 'Unable to write the file'; + } + else + {      + echo 'File written!'; + } - You can optionally set the write mode via the third parameter:: + You can optionally set the write mode via the third parameter:: - write_file('./path/to/file.php', $data, 'r+'); + write_file('./path/to/file.php', $data, 'r+'); - The default mode is 'wb'. Please see the `PHP user guide `_ - for mode options. + The default mode is 'wb'. Please see the `PHP user guide `_ + for mode options. - .. note:: In order for this function to write data to a file, its permissions must - be set such that it is writable. If the file does not already exist, - then the directory containing it must be writable. + .. note:: In order for this function to write data to a file, its permissions must + be set such that it is writable. If the file does not already exist, + then the directory containing it must be writable. - .. note:: The path is relative to your main site index.php file, NOT your - controller or view files. CodeIgniter uses a front controller so paths - are always relative to the main site index. + .. note:: The path is relative to your main site index.php file, NOT your + controller or view files. CodeIgniter uses a front controller so paths + are always relative to the main site index. - .. note:: This function acquires an exclusive lock on the file while writing to it. + .. note:: This function acquires an exclusive lock on the file while writing to it. .. php:function:: delete_files($path[, $delDir = FALSE[, $htdocs = FALSE[, $hidden = FALSE]]]) - :param string $path: Directory path - :param bool $delDir: Whether to also delete directories - :param bool $htdocs: Whether to skip deleting .htaccess and index page files - :param bool $hidden: Whether to also delete hidden files (files beginning with a period) - :returns: TRUE on success, FALSE in case of an error - :rtype: bool + :param string $path: Directory path + :param bool $delDir: Whether to also delete directories + :param bool $htdocs: Whether to skip deleting .htaccess and index page files + :param bool $hidden: Whether to also delete hidden files (files beginning with a period) + :returns: TRUE on success, FALSE in case of an error + :rtype: bool - Deletes ALL files contained in the supplied path. + Deletes ALL files contained in the supplied path. - Example:: + Example:: - delete_files('./path/to/directory/'); + delete_files('./path/to/directory/'); - If the second parameter is set to TRUE, any directories contained within the supplied - root path will be deleted as well. + If the second parameter is set to TRUE, any directories contained within the supplied + root path will be deleted as well. - Example:: + Example:: - delete_files('./path/to/directory/', TRUE); + delete_files('./path/to/directory/', TRUE); - .. note:: The files must be writable or owned by the system in order to be deleted. + .. note:: The files must be writable or owned by the system in order to be deleted. .. php:function:: get_filenames($source_dir[, $include_path = FALSE]) - :param string $source_dir: Directory path - :param bool|null $include_path: Whether to include the path as part of the filename; false for no path, null for the path relative to $source_dir, true for the full path - :param bool $hidden: Whether to include hidden files (files beginning with a period) - :returns: An array of file names - :rtype: array + :param string $source_dir: Directory path + :param bool|null $include_path: Whether to include the path as part of the filename; false for no path, null for the path relative to $source_dir, true for the full path + :param bool $hidden: Whether to include hidden files (files beginning with a period) + :returns: An array of file names + :rtype: array - Takes a server path as input and returns an array containing the names of all files - contained within it. The file path can optionally be added to the file names by setting - the second parameter to 'relative' for relative paths or any other non-empty value for - a full file path. + Takes a server path as input and returns an array containing the names of all files + contained within it. The file path can optionally be added to the file names by setting + the second parameter to 'relative' for relative paths or any other non-empty value for + a full file path. - Example:: + Example:: - $controllers = get_filenames(APPPATH.'controllers/'); + $controllers = get_filenames(APPPATH.'controllers/'); .. php:function:: get_dir_file_info($source_dir, $top_level_only) - :param string $source_dir: Directory path - :param bool $top_level_only: Whether to look only at the specified directory (excluding sub-directories) - :returns: An array containing info on the supplied directory's contents - :rtype: array + :param string $source_dir: Directory path + :param bool $top_level_only: Whether to look only at the specified directory (excluding sub-directories) + :returns: An array containing info on the supplied directory's contents + :rtype: array - Reads the specified directory and builds an array containing the filenames, filesize, - dates, and permissions. Sub-folders contained within the specified path are only read - if forced by sending the second parameter to FALSE, as this can be an intensive - operation. + Reads the specified directory and builds an array containing the filenames, filesize, + dates, and permissions. Sub-folders contained within the specified path are only read + if forced by sending the second parameter to FALSE, as this can be an intensive + operation. - Example:: + Example:: - $models_info = get_dir_file_info(APPPATH.'models/'); + $models_info = get_dir_file_info(APPPATH.'models/'); .. php:function:: get_file_info($file[, $returned_values = ['name', 'server_path', 'size', 'date']]) - :param string $file: File path - :param array|string $returned_values: What type of info to return to be passed as array or comma separated string - :returns: An array containing info on the specified file or FALSE on failure - :rtype: array + :param string $file: File path + :param array|string $returned_values: What type of info to return to be passed as array or comma separated string + :returns: An array containing info on the specified file or FALSE on failure + :rtype: array - Given a file and path, returns (optionally) the *name*, *path*, *size* and *date modified* - information attributes for a file. Second parameter allows you to explicitly declare what - information you want returned. + Given a file and path, returns (optionally) the *name*, *path*, *size* and *date modified* + information attributes for a file. Second parameter allows you to explicitly declare what + information you want returned. - Valid ``$returned_values`` options are: `name`, `size`, `date`, `readable`, `writeable`, - `executable` and `fileperms`. + Valid ``$returned_values`` options are: `name`, `size`, `date`, `readable`, `writeable`, + `executable` and `fileperms`. .. php:function:: symbolic_permissions($perms) - :param int $perms: Permissions - :returns: Symbolic permissions string - :rtype: string + :param int $perms: Permissions + :returns: Symbolic permissions string + :rtype: string - Takes numeric permissions (such as is returned by ``fileperms()``) and returns - standard symbolic notation of file permissions. + Takes numeric permissions (such as is returned by ``fileperms()``) and returns + standard symbolic notation of file permissions. - :: + :: - echo symbolic_permissions(fileperms('./index.php')); // -rw-r--r-- + echo symbolic_permissions(fileperms('./index.php')); // -rw-r--r-- .. php:function:: octal_permissions($perms) - :param int $perms: Permissions - :returns: Octal permissions string - :rtype: string + :param int $perms: Permissions + :returns: Octal permissions string + :rtype: string - Takes numeric permissions (such as is returned by ``fileperms()``) and returns - a three character octal notation of file permissions. + Takes numeric permissions (such as is returned by ``fileperms()``) and returns + a three character octal notation of file permissions. - :: + :: - echo octal_permissions(fileperms('./index.php')); // 644 + echo octal_permissions(fileperms('./index.php')); // 644 .. php:function:: set_realpath($path[, $check_existence = FALSE]) - :param string $path: Path - :param bool $check_existence: Whether to check if the path actually exists - :returns: An absolute path - :rtype: string + :param string $path: Path + :param bool $check_existence: Whether to check if the path actually exists + :returns: An absolute path + :rtype: string - This function will return a server path without symbolic links or - relative directory structures. An optional second argument will - cause an error to be triggered if the path cannot be resolved. + This function will return a server path without symbolic links or + relative directory structures. An optional second argument will + cause an error to be triggered if the path cannot be resolved. - Examples:: + Examples:: - $file = '/etc/php5/apache2/php.ini'; - echo set_realpath($file); // Prints '/etc/php5/apache2/php.ini' + $file = '/etc/php5/apache2/php.ini'; + echo set_realpath($file); // Prints '/etc/php5/apache2/php.ini' - $non_existent_file = '/path/to/non-exist-file.txt'; - echo set_realpath($non_existent_file, TRUE); // Shows an error, as the path cannot be resolved - echo set_realpath($non_existent_file, FALSE); // Prints '/path/to/non-exist-file.txt' + $non_existent_file = '/path/to/non-exist-file.txt'; + echo set_realpath($non_existent_file, TRUE); // Shows an error, as the path cannot be resolved + echo set_realpath($non_existent_file, FALSE); // Prints '/path/to/non-exist-file.txt' - $directory = '/etc/php5'; - echo set_realpath($directory); // Prints '/etc/php5/' + $directory = '/etc/php5'; + echo set_realpath($directory); // Prints '/etc/php5/' - $non_existent_directory = '/path/to/nowhere'; - echo set_realpath($non_existent_directory, TRUE); // Shows an error, as the path cannot be resolved - echo set_realpath($non_existent_directory, FALSE); // Prints '/path/to/nowhere' + $non_existent_directory = '/path/to/nowhere'; + echo set_realpath($non_existent_directory, TRUE); // Shows an error, as the path cannot be resolved + echo set_realpath($non_existent_directory, FALSE); // Prints '/path/to/nowhere' diff --git a/user_guide_src/source/helpers/form_helper.rst b/user_guide_src/source/helpers/form_helper.rst index 0a73100ed403..85f11248a80b 100644 --- a/user_guide_src/source/helpers/form_helper.rst +++ b/user_guide_src/source/helpers/form_helper.rst @@ -17,7 +17,7 @@ Loading this Helper This helper is loaded using the following code:: - helper('form'); + helper('form'); Escaping field values ===================== @@ -29,21 +29,21 @@ elements. In order to do that safely, you'll need to use Consider the following example:: - $string = 'Here is a string containing "quoted" text.'; + $string = 'Here is a string containing "quoted" text.'; - + Since the above string contains a set of quotes, it will cause the form to break. The :php:func:`esc()` function converts HTML special characters so that it can be used safely:: - + .. note:: If you use any of the form helper functions listed on this page, - and you pass values as an associative array, - the form values will be automatically escaped, so there is no need - to call this function. Use it only if you are creating your own - form elements, which you would pass as strings. + and you pass values as an associative array, + the form values will be automatically escaped, so there is no need + to call this function. Use it only if you are creating your own + form elements, which you would pass as strings. Available Functions =================== @@ -52,637 +52,637 @@ The following functions are available: .. php:function:: form_open([$action = ''[, $attributes = ''[, $hidden = []]]]) - :param string $action: Form action/target URI string - :param mixed $attributes: HTML attributes, as an array or escaped string - :param array $hidden: An array of hidden fields' definitions - :returns: An HTML form opening tag - :rtype: string + :param string $action: Form action/target URI string + :param mixed $attributes: HTML attributes, as an array or escaped string + :param array $hidden: An array of hidden fields' definitions + :returns: An HTML form opening tag + :rtype: string - Creates an opening form tag with a base URL **built from your config preferences**. - It will optionally let you add form attributes and hidden input fields, and - will always add the `accept-charset` attribute based on the charset value in your - config file. + Creates an opening form tag with a base URL **built from your config preferences**. + It will optionally let you add form attributes and hidden input fields, and + will always add the `accept-charset` attribute based on the charset value in your + config file. - The main benefit of using this tag rather than hard coding your own HTML is that - it permits your site to be more portable in the event your URLs ever change. + The main benefit of using this tag rather than hard coding your own HTML is that + it permits your site to be more portable in the event your URLs ever change. - Here's a simple example:: + Here's a simple example:: - echo form_open('email/send'); + echo form_open('email/send'); - The above example would create a form that points to your base URL plus the - "email/send" URI segments, like this:: + The above example would create a form that points to your base URL plus the + "email/send" URI segments, like this:: -
+ - You can also add {locale} like the following:: + You can also add {locale} like the following:: - echo form_open('{locale}/email/send'); + echo form_open('{locale}/email/send'); - The above example would create a form that points to your base URL plus the current request locale with - "email/send" URI segments, like this:: + The above example would create a form that points to your base URL plus the current request locale with + "email/send" URI segments, like this:: - + - **Adding Attributes** + **Adding Attributes** - Attributes can be added by passing an associative array to the second - parameter, like this:: + Attributes can be added by passing an associative array to the second + parameter, like this:: - $attributes = ['class' => 'email', 'id' => 'myform']; - echo form_open('email/send', $attributes); + $attributes = ['class' => 'email', 'id' => 'myform']; + echo form_open('email/send', $attributes); - Alternatively, you can specify the second parameter as a string:: + Alternatively, you can specify the second parameter as a string:: - echo form_open('email/send', 'class="email" id="myform"'); + echo form_open('email/send', 'class="email" id="myform"'); - The above examples would create a form similar to this:: + The above examples would create a form similar to this:: - + - If CSRF filter is turned on `form_open()` will generate CSRF field at the beginning of the form. You can specify ID of this field by passing csrf_id as one of the ``$attribute`` array:: + If CSRF filter is turned on `form_open()` will generate CSRF field at the beginning of the form. You can specify ID of this field by passing csrf_id as one of the ``$attribute`` array:: - form_open('/u/sign-up', ['csrf_id' => 'my-id']); + echo form_open('/u/sign-up', ['csrf_id' => 'my-id']); - will return:: + will return:: - - + + - **Adding Hidden Input Fields** + **Adding Hidden Input Fields** - Hidden fields can be added by passing an associative array to the - third parameter, like this:: + Hidden fields can be added by passing an associative array to the + third parameter, like this:: - $hidden = ['username' => 'Joe', 'member_id' => '234']; - echo form_open('email/send', '', $hidden); + $hidden = ['username' => 'Joe', 'member_id' => '234']; + echo form_open('email/send', '', $hidden); - You can skip the second parameter by passing any false value to it. + You can skip the second parameter by passing any false value to it. - The above example would create a form similar to this:: + The above example would create a form similar to this:: - - - + + + .. php:function:: form_open_multipart([$action = ''[, $attributes = ''[, $hidden = []]]]) - :param string $action: Form action/target URI string - :param mixed $attributes: HTML attributes, as an array or escaped string - :param array $hidden: An array of hidden fields' definitions - :returns: An HTML multipart form opening tag - :rtype: string + :param string $action: Form action/target URI string + :param mixed $attributes: HTML attributes, as an array or escaped string + :param array $hidden: An array of hidden fields' definitions + :returns: An HTML multipart form opening tag + :rtype: string - This function is identical to :php:func:`form_open()` above, - except that it adds a *multipart* attribute, which is necessary if you - would like to use the form to upload files with. + This function is identical to :php:func:`form_open()` above, + except that it adds a *multipart* attribute, which is necessary if you + would like to use the form to upload files with. .. php:function:: form_hidden($name[, $value = '']) - :param string $name: Field name - :param string $value: Field value - :returns: An HTML hidden input field tag - :rtype: string + :param string $name: Field name + :param string $value: Field value + :returns: An HTML hidden input field tag + :rtype: string - Lets you generate hidden input fields. You can either submit a - name/value string to create one field:: + Lets you generate hidden input fields. You can either submit a + name/value string to create one field:: - form_hidden('username', 'johndoe'); - // Would produce: + form_hidden('username', 'johndoe'); + // Would produce: - ... or you can submit an associative array to create multiple fields:: + ... or you can submit an associative array to create multiple fields:: - $data = [ - 'name' => 'John Doe', - 'email' => 'john@example.com', - 'url' => 'http://example.com' - ]; + $data = [ + 'name' => 'John Doe', + 'email' => 'john@example.com', + 'url' => 'http://example.com' + ]; - echo form_hidden($data); + echo form_hidden($data); - /* - Would produce: - - - - */ + /* + Would produce: + + + + */ - You can also pass an associative array to the value field:: + You can also pass an associative array to the value field:: - $data = [ - 'name' => 'John Doe', - 'email' => 'john@example.com', - 'url' => 'http://example.com' - ]; + $data = [ + 'name' => 'John Doe', + 'email' => 'john@example.com', + 'url' => 'http://example.com' + ]; - echo form_hidden('my_array', $data); + echo form_hidden('my_array', $data); - /* - Would produce: + /* + Would produce: - - - - */ + + + + */ - If you want to create hidden input fields with extra attributes:: + If you want to create hidden input fields with extra attributes:: - $data = [ - 'type' => 'hidden', - 'name' => 'email', - 'id' => 'hiddenemail', - 'value' => 'john@example.com', - 'class' => 'hiddenemail' - ]; + $data = [ + 'type' => 'hidden', + 'name' => 'email', + 'id' => 'hiddenemail', + 'value' => 'john@example.com', + 'class' => 'hiddenemail' + ]; - echo form_input($data); + echo form_input($data); - /* - Would produce: + /* + Would produce: - - */ + + */ .. php:function:: form_input([$data = ''[, $value = ''[, $extra = ''[, $type = 'text']]]]) - :param array $data: Field attributes data - :param string $value: Field value - :param mixed $extra: Extra attributes to be added to the tag either as an array or a literal string - :param string $type: The type of input field. i.e., 'text', 'email', 'number', etc. - :returns: An HTML text input field tag - :rtype: string + :param array $data: Field attributes data + :param string $value: Field value + :param mixed $extra: Extra attributes to be added to the tag either as an array or a literal string + :param string $type: The type of input field. i.e., 'text', 'email', 'number', etc. + :returns: An HTML text input field tag + :rtype: string - Lets you generate a standard text input field. You can minimally pass - the field name and value in the first and second parameter:: + Lets you generate a standard text input field. You can minimally pass + the field name and value in the first and second parameter:: - echo form_input('username', 'johndoe'); + echo form_input('username', 'johndoe'); - Or you can pass an associative array containing any data you wish your - form to contain:: + Or you can pass an associative array containing any data you wish your + form to contain:: - $data = [ - 'name' => 'username', - 'id' => 'username', - 'value' => 'johndoe', - 'maxlength' => '100', - 'size' => '50', - 'style' => 'width:50%' - ]; + $data = [ + 'name' => 'username', + 'id' => 'username', + 'value' => 'johndoe', + 'maxlength' => '100', + 'size' => '50', + 'style' => 'width:50%' + ]; - echo form_input($data); + echo form_input($data); - /* - Would produce: + /* + Would produce: - - */ + + */ - If you would like your form to contain some additional data, like - JavaScript, you can pass it as a string in the third parameter:: + If you would like your form to contain some additional data, like + JavaScript, you can pass it as a string in the third parameter:: - $js = 'onClick="some_function()"'; - echo form_input('username', 'johndoe', $js); + $js = 'onClick="some_function()"'; + echo form_input('username', 'johndoe', $js); - Or you can pass it as an array:: + Or you can pass it as an array:: - $js = ['onClick' => 'some_function();']; - echo form_input('username', 'johndoe', $js); + $js = ['onClick' => 'some_function();']; + echo form_input('username', 'johndoe', $js); - To support the expanded range of HTML5 input fields, you can pass an input type in as the fourth parameter:: + To support the expanded range of HTML5 input fields, you can pass an input type in as the fourth parameter:: - echo form_input('email', 'joe@example.com', ['placeholder' => 'Email Address...'], 'email'); + echo form_input('email', 'joe@example.com', ['placeholder' => 'Email Address...'], 'email'); - /* - Would produce: + /* + Would produce: - - */ + + */ .. php:function:: form_password([$data = ''[, $value = ''[, $extra = '']]]) - :param array $data: Field attributes data - :param string $value: Field value - :param mixed $extra: Extra attributes to be added to the tag either as an array or a literal string - :returns: An HTML password input field tag - :rtype: string + :param array $data: Field attributes data + :param string $value: Field value + :param mixed $extra: Extra attributes to be added to the tag either as an array or a literal string + :returns: An HTML password input field tag + :rtype: string - This function is identical in all respects to the :php:func:`form_input()` - function above except that it uses the "password" input type. + This function is identical in all respects to the :php:func:`form_input()` + function above except that it uses the "password" input type. .. php:function:: form_upload([$data = ''[, $value = ''[, $extra = '']]]) - :param array $data: Field attributes data - :param string $value: Field value - :param mixed $extra: Extra attributes to be added to the tag either as an array or a literal string - :returns: An HTML file upload input field tag - :rtype: string + :param array $data: Field attributes data + :param string $value: Field value + :param mixed $extra: Extra attributes to be added to the tag either as an array or a literal string + :returns: An HTML file upload input field tag + :rtype: string - This function is identical in all respects to the :php:func:`form_input()` - function above except that it uses the "file" input type, allowing it to - be used to upload files. + This function is identical in all respects to the :php:func:`form_input()` + function above except that it uses the "file" input type, allowing it to + be used to upload files. .. php:function:: form_textarea([$data = ''[, $value = ''[, $extra = '']]]) - :param array $data: Field attributes data - :param string $value: Field value - :param mixed $extra: Extra attributes to be added to the tag either as an array or a literal string - :returns: An HTML textarea tag - :rtype: string + :param array $data: Field attributes data + :param string $value: Field value + :param mixed $extra: Extra attributes to be added to the tag either as an array or a literal string + :returns: An HTML textarea tag + :rtype: string - This function is identical in all respects to the :php:func:`form_input()` - function above except that it generates a "textarea" type. + This function is identical in all respects to the :php:func:`form_input()` + function above except that it generates a "textarea" type. - .. note:: Instead of the *maxlength* and *size* attributes in the above example, - you will instead specify *rows* and *cols*. + .. note:: Instead of the *maxlength* and *size* attributes in the above example, + you will instead specify *rows* and *cols*. .. php:function:: form_dropdown([$name = ''[, $options = [][, $selected = [][, $extra = '']]]]) - :param string $name: Field name - :param array $options: An associative array of options to be listed - :param array $selected: List of fields to mark with the *selected* attribute - :param mixed $extra: Extra attributes to be added to the tag either as an array or a literal string - :returns: An HTML dropdown select field tag - :rtype: string - - Lets you create a standard drop-down field. The first parameter will - contain the name of the field, the second parameter will contain an - associative array of options, and the third parameter will contain the - value you wish to be selected. You can also pass an array of multiple - items through the third parameter, and the helper will create a - multiple select for you. - - Example:: - - $options = [ - 'small' => 'Small Shirt', - 'med' => 'Medium Shirt', - 'large' => 'Large Shirt', - 'xlarge' => 'Extra Large Shirt', - ]; - - $shirts_on_sale = ['small', 'large']; - echo form_dropdown('shirts', $options, 'large'); - - /* - Would produce: - - - */ - - echo form_dropdown('shirts', $options, $shirts_on_sale); - - /* - Would produce: - - - */ - - If you would like the opening + + + + + + */ + + echo form_dropdown('shirts', $options, $shirts_on_sale); + + /* + Would produce: + + + */ + + If you would like the opening + echo form_checkbox('newsletter', 'accept', TRUE); + // Would produce: - The third parameter contains a boolean TRUE/FALSE to determine whether - the box should be checked or not. + The third parameter contains a boolean TRUE/FALSE to determine whether + the box should be checked or not. - Similar to the other form functions in this helper, you can also pass an - array of attributes to the function:: + Similar to the other form functions in this helper, you can also pass an + array of attributes to the function:: - $data = [ - 'name' => 'newsletter', - 'id' => 'newsletter', - 'value' => 'accept', - 'checked' => TRUE, - 'style' => 'margin:10px' - ]; + $data = [ + 'name' => 'newsletter', + 'id' => 'newsletter', + 'value' => 'accept', + 'checked' => TRUE, + 'style' => 'margin:10px' + ]; - echo form_checkbox($data); - // Would produce: + echo form_checkbox($data); + // Would produce: - Also as with other functions, if you would like the tag to contain - additional data like JavaScript, you can pass it as a string in the - fourth parameter:: + Also as with other functions, if you would like the tag to contain + additional data like JavaScript, you can pass it as a string in the + fourth parameter:: - $js = 'onClick="some_function()"'; - echo form_checkbox('newsletter', 'accept', TRUE, $js); + $js = 'onClick="some_function()"'; + echo form_checkbox('newsletter', 'accept', TRUE, $js); - Or you can pass it as an array:: + Or you can pass it as an array:: - $js = ['onClick' => 'some_function();']; - echo form_checkbox('newsletter', 'accept', TRUE, $js); + $js = ['onClick' => 'some_function();']; + echo form_checkbox('newsletter', 'accept', TRUE, $js); .. php:function:: form_radio([$data = ''[, $value = ''[, $checked = FALSE[, $extra = '']]]]) - :param array $data: Field attributes data - :param string $value: Field value - :param bool $checked: Whether to mark the radio button as being *checked* - :param mixed $extra: Extra attributes to be added to the tag either as an array or a literal string - :returns: An HTML radio input tag - :rtype: string + :param array $data: Field attributes data + :param string $value: Field value + :param bool $checked: Whether to mark the radio button as being *checked* + :param mixed $extra: Extra attributes to be added to the tag either as an array or a literal string + :returns: An HTML radio input tag + :rtype: string - This function is identical in all respects to the :php:func:`form_checkbox()` - function above except that it uses the "radio" input type. + This function is identical in all respects to the :php:func:`form_checkbox()` + function above except that it uses the "radio" input type. .. php:function:: form_label([$label_text = ''[, $id = ''[, $attributes = []]]]) - :param string $label_text: Text to put in the