| | 1722 | * Returns a <select> tag, populated with a range of numbers |
|---|
| | 1723 | * |
|---|
| | 1724 | * By default, the select_number_tag generates a list of numbers from 1 - 10, with an incremental value of 1. These values |
|---|
| | 1725 | * can be easily changed by passing one or several <i>$options</i>. Numbers can be either positive or negative, integers or decimals, |
|---|
| | 1726 | * and can be incremented by any number, decimal or integer. If you require the range of numbers to be listed in descending order, pass |
|---|
| | 1727 | * the 'reverse' option to easily display the list of numbers in the opposite direction. |
|---|
| | 1728 | * |
|---|
| | 1729 | * <b>Options:</b> |
|---|
| | 1730 | * - include_blank - Includes a blank <option> tag at the beginning of the string with an empty value. |
|---|
| | 1731 | * - include_custom - Includes an <option> tag with a custom display title at the beginning of the string with an empty value. |
|---|
| | 1732 | * - multiple - If set to true, the select tag will allow multiple numbers to be selected at once. |
|---|
| | 1733 | * - start - The first number in the list. If not specified, the default value is 1. |
|---|
| | 1734 | * - end - The last number in the list. If not specified, the default value is 10. |
|---|
| | 1735 | * - increment - The number by which to increase each number in the list by until the number is greater than or equal to the 'end' option. |
|---|
| | 1736 | * If not specified, the default value is 1. |
|---|
| | 1737 | * - reverse - Reverses the order of numbers so they are display in descending order |
|---|
| | 1738 | * |
|---|
| | 1739 | * <b>Examples:</b> |
|---|
| | 1740 | * <code> |
|---|
| | 1741 | * echo select_number_tag('rating', '', array('reverse' => true)); |
|---|
| | 1742 | * </code> |
|---|
| | 1743 | * |
|---|
| | 1744 | * <code> |
|---|
| | 1745 | * echo echo select_number_tag('tax_rate', '0.07', array('start' => '0.05', 'end' => '0.09', 'increment' => '0.01')); |
|---|
| | 1746 | * </code> |
|---|
| | 1747 | * |
|---|
| | 1748 | * <code> |
|---|
| | 1749 | * echo select_number_tag('limit', 5, array('start' => 5, 'end' => 120, 'increment' => 15)); |
|---|
| | 1750 | * </code> |
|---|
| | 1751 | * |
|---|
| | 1752 | * @param string field name |
|---|
| | 1753 | * @param string the selected option |
|---|
| | 1754 | * @param array <i>$options</i> to manipulate the output of the tag. |
|---|
| | 1755 | * @param array additional HTML compliant <select> tag parameters |
|---|
| | 1756 | * @return string <select> tag populated with a range of numbers. |
|---|
| | 1757 | * @see options_for_select, content_tag |
|---|
| | 1758 | */ |
|---|
| | 1759 | function select_number_tag($name, $value, $options = array(), $html_options = array()) |
|---|
| | 1760 | { |
|---|
| | 1761 | if (!isset($options['start'])) $options['start'] = 1; |
|---|
| | 1762 | if (empty($options['end'])) $options['end'] = 10; |
|---|
| | 1763 | if (empty($options['increment'])) $options['increment'] = 1; |
|---|
| | 1764 | |
|---|
| | 1765 | $range = array(); |
|---|
| | 1766 | |
|---|
| | 1767 | for ($x = $options['start']; $x < ($options['end'] + $options['increment']); $x += $options['increment']) |
|---|
| | 1768 | { |
|---|
| | 1769 | $range[(string) $x] = $x; |
|---|
| | 1770 | } |
|---|
| | 1771 | |
|---|
| | 1772 | if (isset($options['reverse'])) $range = array_reverse($range); |
|---|
| | 1773 | |
|---|
| | 1774 | unset($options['start']); |
|---|
| | 1775 | unset($options['end']); |
|---|
| | 1776 | unset($options['increment']); |
|---|
| | 1777 | unset($options['reverse']); |
|---|
| | 1778 | |
|---|
| | 1779 | return select_tag($name, options_for_select($range, $value, $options), $html_options); |
|---|
| | 1780 | } |
|---|
| | 1781 | |
|---|
| | 1782 | /** |
|---|