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