/** * Prepare the value before saving it to the lead. * * @param mixed $form * @param GF_Field $field * @param mixed $value * @param mixed $input_name * @param mixed $lead_id the current lead ID, used for fields that are processed after other fields have been saved (ie Total, Calculations) * @param mixed $lead passed by the RGFormsModel::create_lead() method, lead ID is not available for leads created by this function * * @return mixed */ public static function prepare_value($form, $field, $value, $input_name, $lead_id, $lead = array()) { $value = $field->get_value_save_entry($value, $form, $input_name, $lead_id, $lead); // special format for Post Category fields if ($field->type == 'post_category') { $full_values = array(); if (!is_array($value)) { $value = explode(',', $value); } foreach ($value as $cat_id) { $cat = get_term($cat_id, 'category'); $full_values[] = !is_wp_error($cat) && is_object($cat) ? $cat->name . ':' . $cat_id : ''; } $value = implode(',', $full_values); } //do not save price fields with blank price if ($field->enablePrice) { $ary = explode('|', $value); $label = count($ary) > 0 ? $ary[0] : ''; $price = count($ary) > 1 ? $ary[1] : ''; $is_empty = strlen(trim($price)) <= 0; if ($is_empty) { $value = ''; } } return $value; }