| @@ 751-799 (lines=49) @@ | ||
| 748 | ||
| 749 | // ------------------------------------------------------------------------ |
|
| 750 | ||
| 751 | if ( ! function_exists('set_checkbox')) |
|
| 752 | { |
|
| 753 | /** |
|
| 754 | * Set Checkbox |
|
| 755 | * |
|
| 756 | * Let's you set the selected value of a checkbox via the value in the POST array. |
|
| 757 | * If Form Validation is active it retrieves the info from the validation class |
|
| 758 | * |
|
| 759 | * @param string |
|
| 760 | * @param string |
|
| 761 | * @param bool |
|
| 762 | * @return string |
|
| 763 | */ |
|
| 764 | function set_checkbox($field, $value = '', $default = FALSE) |
|
| 765 | { |
|
| 766 | $CI =& get_instance(); |
|
| 767 | ||
| 768 | if (isset($CI->form_validation) && is_object($CI->form_validation) && $CI->form_validation->has_rule($field)) |
|
| 769 | { |
|
| 770 | return $CI->form_validation->set_checkbox($field, $value, $default); |
|
| 771 | } |
|
| 772 | ||
| 773 | // Form inputs are always strings ... |
|
| 774 | $value = (string) $value; |
|
| 775 | $input = $CI->input->post($field, FALSE); |
|
| 776 | ||
| 777 | if (is_array($input)) |
|
| 778 | { |
|
| 779 | // Note: in_array('', array(0)) returns TRUE, do not use it |
|
| 780 | foreach ($input as &$v) |
|
| 781 | { |
|
| 782 | if ($value === $v) |
|
| 783 | { |
|
| 784 | return ' checked="checked"'; |
|
| 785 | } |
|
| 786 | } |
|
| 787 | ||
| 788 | return ''; |
|
| 789 | } |
|
| 790 | ||
| 791 | // Unchecked checkbox and radio inputs are not even submitted by browsers ... |
|
| 792 | if ($CI->input->method() === 'post') |
|
| 793 | { |
|
| 794 | return ($input === 'value') ? ' checked="checked"' : ''; |
|
| 795 | } |
|
| 796 | ||
| 797 | return ($default === TRUE) ? ' checked="checked"' : ''; |
|
| 798 | } |
|
| 799 | } |
|
| 800 | ||
| 801 | // ------------------------------------------------------------------------ |
|
| 802 | ||
| @@ 803-851 (lines=49) @@ | ||
| 800 | ||
| 801 | // ------------------------------------------------------------------------ |
|
| 802 | ||
| 803 | if ( ! function_exists('set_radio')) |
|
| 804 | { |
|
| 805 | /** |
|
| 806 | * Set Radio |
|
| 807 | * |
|
| 808 | * Let's you set the selected value of a radio field via info in the POST array. |
|
| 809 | * If Form Validation is active it retrieves the info from the validation class |
|
| 810 | * |
|
| 811 | * @param string $field |
|
| 812 | * @param string $value |
|
| 813 | * @param bool $default |
|
| 814 | * @return string |
|
| 815 | */ |
|
| 816 | function set_radio($field, $value = '', $default = FALSE) |
|
| 817 | { |
|
| 818 | $CI =& get_instance(); |
|
| 819 | ||
| 820 | if (isset($CI->form_validation) && is_object($CI->form_validation) && $CI->form_validation->has_rule($field)) |
|
| 821 | { |
|
| 822 | return $CI->form_validation->set_radio($field, $value, $default); |
|
| 823 | } |
|
| 824 | ||
| 825 | // Form inputs are always strings ... |
|
| 826 | $value = (string) $value; |
|
| 827 | $input = $CI->input->post($field, FALSE); |
|
| 828 | ||
| 829 | if (is_array($input)) |
|
| 830 | { |
|
| 831 | // Note: in_array('', array(0)) returns TRUE, do not use it |
|
| 832 | foreach ($input as &$v) |
|
| 833 | { |
|
| 834 | if ($value === $v) |
|
| 835 | { |
|
| 836 | return ' checked="checked"'; |
|
| 837 | } |
|
| 838 | } |
|
| 839 | ||
| 840 | return ''; |
|
| 841 | } |
|
| 842 | ||
| 843 | // Unchecked checkbox and radio inputs are not even submitted by browsers ... |
|
| 844 | if ($CI->input->method() === 'post') |
|
| 845 | { |
|
| 846 | return ($input === 'value') ? ' checked="checked"' : ''; |
|
| 847 | } |
|
| 848 | ||
| 849 | return ($default === TRUE) ? ' checked="checked"' : ''; |
|
| 850 | } |
|
| 851 | } |
|
| 852 | ||
| 853 | // ------------------------------------------------------------------------ |
|
| 854 | ||