public static function delete_option()
 {
     check_ajax_referer('frm_ajax', 'nonce');
     $field_id = FrmAppHelper::get_post_param('field_id', 0, 'absint');
     $field = FrmField::getOne($field_id);
     // Opt key will NOT be numeric for "Other" options
     $opt_key = FrmAppHelper::get_post_param('opt_key', 0, 'sanitize_title');
     $options = $field->options;
     unset($options[$opt_key]);
     $response = array('other' => true);
     //If the deleted option is an "other" option
     if (FrmFieldsHelper::is_other_opt($opt_key)) {
         //Assume all other options are gone, unless proven otherwise
         $other = false;
         //Check if all other options are really gone
         foreach ($options as $o_key => $o_val) {
             //If there is still an other option in the field, set other to true
             if (FrmFieldsHelper::is_other_opt($o_key)) {
                 $other = true;
                 break;
             }
             unset($o_key, $o_val);
         }
         //If all other options are gone
         if (false === $other) {
             $field_options = maybe_unserialize($field->field_options);
             $field_options['other'] = 0;
             FrmField::update($field_id, array('field_options' => maybe_serialize($field_options)));
             $response = array('other' => false);
         }
     }
     echo json_encode($response);
     FrmField::update($field_id, array('options' => maybe_serialize($options)));
     wp_die();
 }
Example #2
0
 /**
  * Check if current field option is an "other" option
  *
  * @since 2.0
  *
  * @param string $opt_key
  * @return boolean Returns true if current field option is an "Other" option
  */
 public static function is_other_opt($opt_key)
 {
     _deprecated_function(__FUNCTION__, '2.0.6', 'FrmFieldsHelper::is_other_opt');
     return FrmFieldsHelper::is_other_opt($opt_key);
 }
Example #3
0
<?php

if (!is_array($field['options'])) {
    return;
}
foreach ($field['options'] as $opt_key => $opt) {
    $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
    $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
    // Get string for Other text field, if needed
    $other_val = FrmFieldsHelper::get_other_val(compact('opt_key', 'field'));
    $checked = $other_val || isset($field['value']) && (!is_array($field['value']) && $field['value'] == $field_val || is_array($field['value']) && in_array($field_val, $field['value'])) ? ' checked="checked"' : '';
    if (FrmFieldsHelper::is_other_opt($opt_key)) {
        include FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-fields/other-option.php';
    } else {
        include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php';
    }
    unset($checked, $other_val);
}
 /**
  * Get value that belongs in "Other" text box
  *
  * @since 2.0.6
  *
  * @param array $args
  */
 public static function get_other_val($args)
 {
     $defaults = array('opt_key' => 0, 'field' => array(), 'parent' => false, 'pointer' => false);
     $args = wp_parse_args($args, $defaults);
     $opt_key = $args['opt_key'];
     $field = $args['field'];
     $parent = $args['parent'];
     $pointer = $args['pointer'];
     $other_val = '';
     // If option is an "other" option and there is a value set for this field,
     // check if the value belongs in the current "Other" option text field
     if (!FrmFieldsHelper::is_other_opt($opt_key) || !FrmField::is_option_true($field, 'value')) {
         return $other_val;
     }
     // Check posted vals before checking saved values
     // For fields inside repeating sections - note, don't check if $pointer is true because it will often be zero
     if ($parent && isset($_POST['item_meta'][$parent][$pointer]['other'][$field['id']])) {
         if (FrmField::is_field_with_multiple_values($field)) {
             $other_val = isset($_POST['item_meta'][$parent][$pointer]['other'][$field['id']][$opt_key]) ? sanitize_text_field($_POST['item_meta'][$parent][$pointer]['other'][$field['id']][$opt_key]) : '';
         } else {
             $other_val = sanitize_text_field($_POST['item_meta'][$parent][$pointer]['other'][$field['id']]);
         }
         return $other_val;
     } else {
         if (isset($field['id']) && isset($_POST['item_meta']['other'][$field['id']])) {
             // For normal fields
             if (FrmField::is_field_with_multiple_values($field)) {
                 $other_val = isset($_POST['item_meta']['other'][$field['id']][$opt_key]) ? sanitize_text_field($_POST['item_meta']['other'][$field['id']][$opt_key]) : '';
             } else {
                 $other_val = sanitize_text_field($_POST['item_meta']['other'][$field['id']]);
             }
             return $other_val;
         }
     }
     // For checkboxes
     if ($field['type'] == 'checkbox' && is_array($field['value'])) {
         // Check if there is an "other" val in saved value and make sure the
         // "other" val is not equal to the Other checkbox option
         if (isset($field['value'][$opt_key]) && $field['options'][$opt_key] != $field['value'][$opt_key]) {
             $other_val = $field['value'][$opt_key];
         }
     } else {
         /**
          * For radio buttons and dropdowns
          * Check if saved value equals any of the options. If not, set it as the other value.
          */
         foreach ($field['options'] as $opt_key => $opt_val) {
             $temp_val = is_array($opt_val) ? $opt_val['value'] : $opt_val;
             // Multi-select dropdowns - key is not preserved
             if (is_array($field['value'])) {
                 $o_key = array_search($temp_val, $field['value']);
                 if (isset($field['value'][$o_key])) {
                     unset($field['value'][$o_key], $o_key);
                 }
             } else {
                 if ($temp_val == $field['value']) {
                     // For radio and regular dropdowns
                     return '';
                 } else {
                     $other_val = $field['value'];
                 }
             }
             unset($opt_key, $opt_val, $temp_val);
         }
         // For multi-select dropdowns only
         if (is_array($field['value']) && !empty($field['value'])) {
             $other_val = reset($field['value']);
         }
     }
     return $other_val;
 }
 /**
  * Get the HTML ID for hidden other fields inside of repeating sections
  *
  * @since 2.0.8
  * @param array $parts (array of the field name)
  * @param string|boolean|int $opt_key
  * @param string $html_id, pass by reference
  */
 private static function get_html_id_for_hidden_other_fields($parts, $opt_key, &$html_id)
 {
     $field_id = absint($parts[3]);
     $field_key = FrmField::get_type($field_id, 'field_key');
     if ($field_key) {
         $html_id = 'field_' . $field_key . '-' . $parts[1];
         // If checkbox field or multi-select dropdown
         if ($opt_key && FrmFieldsHelper::is_other_opt($opt_key)) {
             $html_id .= '-' . $opt_key . '-otext';
         } else {
             $html_id .= '-otext';
         }
     }
 }
Example #6
0
                        $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field);
                        $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field);
                        $selected = FrmAppHelper::check_selected($field['value'], $field_val);
                        if ($other_opt === false) {
                            $other_args = FrmFieldsHelper::prepare_other_input(compact('field', 'field_name', 'opt_key'), $other_opt, $selected);
                            if (FrmFieldsHelper::is_other_opt($opt_key) && $selected) {
                                $other_checked = true;
                            }
                        }
                        ?>
		<option value="<?php 
                        echo esc_attr($field_val);
                        ?>
" <?php 
                        echo $selected ? ' selected="selected"' : '';
                        echo FrmFieldsHelper::is_other_opt($opt_key) ? ' class="frm_other_trigger"' : '';
                        ?>
><?php 
                        echo $opt == '' ? ' ' : $opt;
                        ?>
</option>
    <?php 
                    }
                    ?>
</select>
<?php 
                    FrmFieldsHelper::include_other_input(array('other_opt' => $other_opt, 'read_only' => $read_only, 'checked' => $other_checked, 'name' => $other_args['name'], 'value' => $other_args['value'], 'field' => $field, 'html_id' => $html_id, 'opt_key' => false));
                }
            } else {
                if ($field['type'] == 'checkbox') {
                    $checked_values = $field['value'];
 /**
  * Get displayed values for separate values, data from entries, and other option.
  * Capitalizes first letter of each option
  *
  * @since 2.0
  *
  * @param array $temp_values
  * @param object $field
  */
 public static function get_displayed_values(&$temp_values, $field)
 {
     $temp_array = array();
     // If data from entries field
     if ($field->type == 'data') {
         // Get DFE text
         foreach ($temp_values as $entry_id => $total) {
             $linked_field = $field->field_options['form_select'];
             $text_val = FrmProEntriesController::get_field_value_shortcode(array('field_id' => $linked_field, 'entry_id' => $entry_id));
             $temp_array[$text_val] = $total;
             unset($entry_id, $total, $linked_field, $text_val);
         }
     } else {
         $other_label = false;
         foreach ($field->options as $opt_key => $opt) {
             if (!$opt) {
                 continue;
             }
             // If field option is "other" option
             if (FrmFieldsHelper::is_other_opt($opt_key)) {
                 // For radio button field, combine all extra counts/totals into one "Other" count/total
                 if ($field->type == 'radio' || $field->type == 'select') {
                     $other_label = strtolower($opt);
                     continue;
                     // For checkbox fields, set value and label
                 } else {
                     $opt_value = strtolower($opt_key);
                     $opt_label = strtolower($opt);
                 }
                 // If using separate values
             } else {
                 if (is_array($opt)) {
                     $opt_label = strtolower($opt['label']);
                     $opt_value = strtolower($opt['value']);
                     if (!$opt_value || !$opt_label) {
                         continue;
                     }
                 } else {
                     $opt_label = $opt_value = strtolower($opt);
                 }
             }
             // Set displayed value total in new array, unset original value in old array
             if (isset($temp_values[$opt_value])) {
                 $temp_array[$opt_label] = $temp_values[$opt_value];
                 unset($temp_values[$opt_value]);
             }
             unset($opt_key, $opt, $opt_label, $opt_value);
         }
         // Applies to radio buttons only (with other option)
         // Combines all extra counts/totals into one "Other" count/total
         if ($other_label) {
             $temp_array[$other_label] = array_sum($temp_values);
         }
     }
     // Copy new array
     $temp_values = $temp_array;
 }