Example #1
0
 /**
  * Returns the value of a $_POST variable
  *
  */
 public static function get_value($field_id, $field_setup = FALSE)
 {
     $array_field = Format::string_explode(str_replace(']', '', $field_id), '[');
     // if multidimensional
     if (count($array_field) > 1) {
         $post_value = NULL;
         foreach ($array_field as $key) {
             if (empty($post_value)) {
                 $post_value = $_POST[$key];
             } elseif ($field_setup['type'] != 'date_select') {
                 $post_value = $post_value[$key];
             }
         }
         // field type = date
         if ($field_setup['type'] == 'date_select' && Read::array_search('day', $post_value, 'key::in') && Read::array_search('month', $post_value, 'key::in') && Read::array_search('year', $post_value, 'key::in')) {
             $post_value = Format::array_join(array($post_value['year'], $post_value['month'], $post_value['day']), '-');
         }
     } else {
         // blisr fields
         if ($field_setup['type'] == 'blisr') {
             $post_value = Form::multistring_post_values($_POST[Form::blisr_unique_id($field_id, TRUE)]);
         } elseif ($field_setup['type'] == 'autocomplete' && $field_setup['metas']['multiple'] === TRUE) {
             $post_value = Form::multistring_post_values($_POST[$field_id . '_autocomplete_receiver']);
         } elseif ($field_setup['type'] == 'date') {
             if ($field_setup['metas']['range'] === TRUE) {
                 if (empty($_POST[$field_id . '_from']) && $field_setup['metas']['readonly'] !== TRUE) {
                     $_POST[$field_id . '_from'] = Format::date(Base::get_date(), 'human');
                 }
                 if (empty($_POST[$field_id . '_to']) && $field_setup['metas']['readonly'] !== TRUE) {
                     $_POST[$field_id . '_to'] = Format::date(Base::get_date(), 'human');
                 }
                 $post_value = array(Format::date($_POST[$field_id . '_from'], 'db'), Format::date($_POST[$field_id . '_to'], 'db'));
                 if ($field_setup['metas']['time']) {
                     if (empty($_POST[$field_id . '_from_time'])) {
                         $_POST[$field_id . '_from_time'] = '12:00';
                     }
                     if (empty($_POST[$field_id . '_to_time'])) {
                         $_POST[$field_id . '_to_time'] = '12:00';
                     }
                     $post_value[0] = Format::array_join(array($post_value[0], $_POST[$field_id . '_from_time']), ' ');
                     $post_value[1] = Format::array_join(array($post_value[1], $_POST[$field_id . '_to_time']), ' ');
                 }
             } else {
                 if (empty($_POST[$field_id]) && $field_setup['metas']['readonly'] !== TRUE) {
                     $_POST[$field_id] = Format::date(Base::get_date(), 'human');
                 }
                 $post_value = Format::date($_POST[$field_id], 'db');
                 if ($field_setup['metas']['time']) {
                     if (empty($_POST[$field_id . '_time'])) {
                         $_POST[$field_id . '_time'] = '12:00';
                     }
                     $post_value = Format::array_join(array($post_value, $_POST[$field_id . '_time']), ' ');
                 }
             }
         } elseif ($field_setup['type'] == 'phone') {
             $post_value = preg_replace('#^\\+#', '00', $_POST[$field_id]);
             $post_value = preg_replace('#\\D+#', '', $post_value);
         } elseif ($field_setup['type'] == 'url') {
             $post_value = Format::string_trim($_POST[$field_id], '/');
         } else {
             $post_value = $_POST[$field_id];
         }
     }
     $value = Form::is_submitted() && !$field_setup['metas']['readonly'] ? $post_value : $field_setup['value'];
     // add on values for special fields
     if (Form::is_submitted() && $field_setup['type'] == 'url' && !empty($value) && strpos($value, '://') === FALSE) {
         $value = 'http://' . $value;
     }
     return !is_array($value) ? trim($value) : $value;
 }