static function validate($text) { // Wordpress will call this function when the settings form is submitted // $text contains the POST options array from the form global $fscf_special_slugs; // List of reserved slug names self::$global_options = FSCF_Util::get_global_options(); self::$form_defaults = FSCF_Util::set_defaults(); if (!isset(self::$form_options)) { self::$form_options = FSCF_Util::get_form_options(self::$current_form, false); } // See if 'donated' status has changed. If so, update global settings. // if the POST variable fs_contact_donated exists, then the checkbox was checked $donated = isset($_POST['fs_contact_donated']) ? 'true' : 'false'; if ($donated != self::$global_options['donated']) { self::$global_options['donated'] = $donated; } if (isset($_POST['fs_dismiss_import_msg'])) { self::$global_options['import_msg'] = false; } // Update global options array based on value of enable_php_sessions // if the POST variable enable_php_session, then the checkbox was checked $php_sessions = isset($_POST['enable_php_sessions']) ? 'true' : 'false'; if ($php_sessions != self::$global_options['enable_php_sessions']) { self::$global_options['enable_php_sessions'] = $php_sessions; } // vcita_auto_install if (!empty($_POST['vcita_auto_install']) && ($_POST['vcita_auto_install'] == 'true' || $_POST['vcita_auto_install'] == 'false')) { self::$global_options['vcita_auto_install'] = $_POST['vcita_auto_install']; } // vcita_dismiss if (!empty($_POST['vcita_dismiss']) && ($_POST['vcita_dismiss'] == 'true' || $_POST['vcita_dismiss'] == 'false')) { self::$global_options['vcita_dismiss'] = $_POST['vcita_dismiss']; } update_option('fs_contact_global', self::$global_options); // Trim trailing spaces FSCF_Util::trim_array($text); // Special processing for certain form fields if ('' == $text['email_to']) { $text['email_to'] = self::$form_defaults['email_to']; } // use default if empty $text['redirect_seconds'] = is_numeric($text['redirect_seconds']) && $text['redirect_seconds'] < 61 ? absint($text['redirect_seconds']) : self::$form_defaults['redirect_seconds']; if ('' == $text['redirect_url']) { $text['redirect_url'] = self::$form_defaults['redirect_url']; } // use default if empty if (!preg_match('/^[0-6]?$/', $text['cal_start_day'])) { $text['cal_start_day'] = self::$form_defaults['cal_start_day']; } $text['attach_types'] = str_replace('.', '', $text['attach_types']); if ('' == $text['attach_size'] || !preg_match('/^([[0-9.]+)([kKmM]?[bB])?$/', $text['attach_size'])) { $text['attach_size'] = self::$form_defaults['attach_size']; } if ('' == $text['auto_respond_from_name']) { $text['auto_respond_from_name'] = self::$form_defaults['auto_respond_from_name']; } // use default if empty if ('' == $text['auto_respond_from_email'] || !FSCF_Util::validate_email($text['auto_respond_from_email'])) { $text['auto_respond_from_email'] = self::$form_defaults['auto_respond_from_email']; } // use default if empty if ($text['auto_respond_reply_to'] == '' || !FSCF_Util::validate_email($text['auto_respond_reply_to'])) { $text['auto_respond_reply_to'] = self::$form_defaults['auto_respond_reply_to']; } // use default if empty // $text['field_size'] = ( is_numeric( $text['field_size'] ) && $text['field_size'] > 14 ) ? absint( $text['field_size'] ) : self::$form_defaults['field_size']; // use default if empty //$text['captcha_field_size'] = ( is_numeric( $text['captcha_field_size'] ) && $text['captcha_field_size'] > 4 ) ? absint( $text['captcha_field_size'] ) : self::$form_defaults['captcha_field_size']; //$text['text_cols'] = absint( $text['text_cols'] ); //$text['text_rows'] = absint( $text['text_rows'] ); if (!empty($text['domain_protect_names'])) { $text['domain_protect_names'] = self::clean_textarea($text['domain_protect_names']); } if (!empty($text['email_to'])) { $text['email_to'] = self::clean_textarea($text['email_to']); } // Use default style settings if styles are empty if (!isset(self::$style_defaults)) { self::$style_defaults = FSCF_Util::set_style_defaults(); } foreach (self::$style_defaults as $key => $val) { //if ( '' == $text[$key] ) // caused error on import settings from some older versions if (!isset($text[$key]) || empty($text[$key])) { $text[$key] = $val; } } // Do we need to reset all styles top this form? if (isset($_POST['fscf_reset_styles'])) { // reset styles feature $text = FSCF_Action::copy_styles(self::$form_defaults, $text); } if (isset($_POST['fscf_reset_styles_top'])) { $style_resets_arr = array('form_style' => 'width:99%; max-width:555px;', 'left_box_style' => 'float:left; width:55%; max-width:270px;', 'right_box_style' => 'float:left; width:235px;', 'clear_style' => 'clear:both;', 'field_left_style' => 'clear:left; float:left; width:99%; max-width:550px; margin-right:10px;', 'field_prefollow_style' => 'clear:left; float:left; width:99%; max-width:250px; margin-right:10px;', 'field_follow_style' => 'float:left; padding-left:10px; width:99%; max-width:250px;', 'title_style' => 'text-align:left; padding-top:5px;', 'field_div_style' => 'text-align:left;', 'captcha_div_style_sm' => 'width:175px; height:50px; padding-top:2px;', 'captcha_div_style_m' => 'width:250px; height:65px; padding-top:2px;', 'captcha_image_style' => 'border-style:none; margin:0; padding:0px; padding-right:5px; float:left;', 'captcha_reload_image_style' => 'border-style:none; margin:0; padding:0px; vertical-align:bottom;', 'submit_div_style' => 'text-align:left; clear:both; padding-top:15px;', 'border_style' => 'border:1px solid black; width:99%; max-width:550px; padding:10px;'); // reset left styles feature foreach ($style_resets_arr as $key => $val) { $text[$key] = $val; } } // end reset styles top if (isset($_POST['fscf_reset_styles_left'])) { $style_resets_arr = array('form_style' => 'width:655px;', 'left_box_style' => 'float:left; width:450px;', 'right_box_style' => 'float:left; width:235px;', 'clear_style' => 'clear:both;', 'field_left_style' => 'clear:left; float:left; margin-right:10px;', 'field_prefollow_style' => 'clear:left; float:left; margin-right:10px;', 'field_follow_style' => 'float:left; padding-left:10px;', 'title_style' => 'width:138px; float:left; clear:left; text-align:right; padding-top:8px; padding-right:10px;', 'field_div_style' => 'text-align:left; float:left; padding-top:10px;', 'captcha_div_style_sm' => 'float:left; width:162px; height:50px; padding-top:5px;', 'captcha_div_style_m' => 'float:left; width:362px; height:65px; padding-top:5px;', 'captcha_image_style' => 'border-style:none; margin:0; padding:0px; padding-right:5px; float:left;', 'captcha_reload_image_style' => 'border-style:none; margin:0; padding:0px; vertical-align:bottom;', 'submit_div_style' => 'padding-left:146px; float:left; clear:left; text-align:left; padding-top:15px;', 'border_style' => 'border:1px solid black; width:99%; max-width:450px; padding:10px;'); // reset left styles feature foreach ($style_resets_arr as $key => $val) { $text[$key] = $val; } } // end reset styles left if (isset($_POST['fscf_reset_styles_labels'])) { $style_resets_arr = array('border_enable' => 'false', 'required_style' => 'text-align:left;', 'required_text_style' => 'text-align:left;', 'hint_style' => 'font-size:x-small; font-weight:normal;', 'error_style' => 'text-align:left; color:red;', 'redirect_style' => 'text-align:left;', 'fieldset_style' => 'border:1px solid black; width:97%; max-width:500px; padding:10px;', 'label_style' => 'display:inline;', 'option_label_style' => 'display:inline;', 'field_style' => 'text-align:left; margin:0; width:99%; max-width:250px;', 'captcha_input_style' => 'text-align:left; margin:0; width:50px;', 'textarea_style' => 'text-align:left; margin:0; width:99%; max-width:250px; height:120px;', 'select_style' => 'text-align:left;', 'checkbox_style' => 'width:13px;', 'radio_style' => 'width:13px;', 'placeholder_style' => 'opacity:0.6; color:#333333;', 'button_style' => 'cursor:pointer; margin:0;', 'reset_style' => 'cursor:pointer; margin:0;', 'vcita_button_style' => 'text-decoration:none; display:block; text-align:center; background:linear-gradient(to bottom, #ed6a31 0%, #e55627 100%); color:#fff !important; padding:10px;', 'vcita_div_button_style' => 'border-left:1px dashed #ccc; margin-top:25px; height:50px; padding:8px 20px;', 'powered_by_style' => 'font-size:x-small; font-weight:normal; padding-top:5px; text-align:center;'); // reset label styles feature foreach ($style_resets_arr as $key => $val) { $text[$key] = $val; } } // end reset styles left // List of all checkbox settings names (except for checkboxes in fields) $checkboxes = array('email_from_enforced', 'preserve_space_enable', 'double_email', 'name_case_enable', 'sender_info_enable', 'domain_protect', 'email_check_dns', 'email_html', 'akismet_disable', 'captcha_enable', 'akismet_send_anyway', 'captcha_small', 'email_hide_empty', 'email_keep_attachments', 'print_form_enable', 'captcha_perm', 'honeypot_enable', 'redirect_enable', 'redirect_query', 'redirect_email_off', 'silent_email_off', 'export_email_off', 'ex_fields_after_msg', 'email_inline_label', 'textarea_html_allow', 'enable_areyousure', 'enable_submit_oneclick', 'auto_respond_enable', 'auto_respond_html', 'req_field_indicator_enable', 'req_field_label_enable', 'border_enable', 'anchor_enable', 'aria_required', 'auto_fill_enable', 'enable_reset', 'enable_credit_link'); // Set missing checkbox values to 'false' because these boxes were unchecked // html form checkboxes do not return anything in POST if unchecked // $text = array_merge($unchecked, $text); foreach ($checkboxes as $checkbox) { if (!isset($text[$checkbox])) { $text[$checkbox] = 'false'; } } // Sanitize settings fields $html_fields = array('welcome', 'after_form_note', 'req_field_indicator', 'text_message_sent', 'success_page_html'); if ('true' == $text['auto_respond_html']) { $html_fields[] = 'auto_respond_message'; } foreach ($text as $key => $value) { if (is_string($value)) { if (in_array($key, $html_fields)) { //$text[$key] = wp_filter_kses( $value ); //strips too much $text[$key] = $value; } else { $text[$key] = strip_tags($value); } } } // Process contact form fields $slug_list = $fscf_special_slugs; // The $special_slugs list is also used in FSCF_Display::get_query_parms() // $special_slugs = array( 'f_name', 'm_name', 'mi_name', 'l_name', 'email2', 'mailto_id', 'subject_id' ); $select_type_fields = array('checkbox-multiple', 'select', 'select-multiple', 'radio'); // none of the field slugs can be the same as a post type rewrite_slug // or you will get "page not found" when posting the form with that field filled in self::get_post_types_slugs(); $slug_list = array(); if (isset(self::$form_options) && !empty(self::$form_options['fields'])) { foreach (self::$form_options['fields'] as $key => $field) { $slug_list[] = $field['slug']; } } $bad_slugs = array(); foreach (self::$post_types_slugs as $key => $slug) { if (in_array(strtolower($slug), $slug_list)) { $bad_slugs[] = $slug; } } foreach ($text['fields'] as $key => $field) { if (isset($field['delete']) && "true" == $field['delete']) { // Delete the field unset($text['fields'][$key]); } else { unset($text['fields']['$key']['delete']); // Don't need to keep this // Add 'false' to any missing checkboxes for fields if (!isset($field['req'])) { $text['fields'][$key]['req'] = 'false'; } if (!isset($field['disable'])) { $text['fields'][$key]['disable'] = 'false'; } if (!isset($field['follow'])) { $text['fields'][$key]['follow'] = 'false'; } if (!isset($field['inline'])) { $text['fields'][$key]['inline'] = 'false'; } if (!isset($field['hide_label'])) { $text['fields'][$key]['hide_label'] = 'false'; } if (!isset($field['placeholder'])) { $text['fields'][$key]['placeholder'] = 'false'; } // Sanitize html in form field settings foreach ($field as $k => $v) { if (is_string($v)) { //if ( 'notes' == $k || 'notes_after' == $k ) $text['fields'][$key][$k] = wp_filter_kses( $v ); //strips too much if ('notes' == $k || 'notes_after' == $k) { $text['fields'][$key][$k] = $v; } else { $text['fields'][$key][$k] = strip_tags($v); } // strip html tags } } // Make sure the field name is not blank if (empty($field['label'])) { $text['fields'][$key]['label'] = sprintf(__('Field %s', 'si-contact-form'), $key); $temp = sprintf(__('Field label cannot be blank. Label set to "Field %s". To delete a field, use the delete option.', 'si-contact-form'), $key); add_settings_error('fscf_field_settings', 'missing-label', $temp); } // Sanitize the slug $slug_changed = false; if (!empty($field['slug']) && in_array(strtolower($field['slug']), $bad_slugs)) { $slug_changed = true; } if (empty($field['slug'])) { // no slug, so make one from the label // the sanitize title function encodes UTF-8 characters, so we need to undo that // this line croaked on some chinese characters //$field['slug'] = substr( urldecode(sanitize_title_with_dashes(remove_accents($field['label']))), 0, FSCF_MAX_SLUG_LEN ); $field['slug'] = remove_accents($field['label']); $field['slug'] = preg_replace('~([^a-zA-Z\\d_ .-])~', '', $field['slug']); $field['slug'] = substr(urldecode(sanitize_title_with_dashes($field['slug'])), 0, FSCF_MAX_SLUG_LEN); if ($field['slug'] == '') { $field['slug'] = 'na'; } if ('-' == substr($field['slug'], strlen($field['slug']) - 1, 1)) { $field['slug'] = substr($field['slug'], 0, strlen($field['slug']) - 1); } $slug_changed = true; } else { if (empty(self::$form_options['fields'][$key]['slug']) || $field['slug'] != self::$form_options['fields'][$key]['slug']) { // The slug has changed, so sanitize it // this line croaked on some chinese characters //$field['slug'] = substr( urldecode(sanitize_title_with_dashes(remove_accents($field['slug']))), 0, FSCF_MAX_SLUG_LEN ); $field['slug'] = remove_accents($field['slug']); $field['slug'] = preg_replace('~([^a-zA-Z\\d_ .-])~', '', $field['slug']); $field['slug'] = substr(urldecode(sanitize_title_with_dashes($field['slug'])), 0, FSCF_MAX_SLUG_LEN); if ($field['slug'] == '') { $field['slug'] = 'na'; } $slug_changed = true; } } // Make sure the slug is unique if ($slug_changed) { $text['fields'][$key]['slug'] = self::check_slug($field['slug'], $slug_list); } } $slug_list[] = $text['fields'][$key]['slug']; // If a select type field, make sure the select options list is not empty if (in_array($field['type'], $select_type_fields)) { // remove blank lines and trim options if (!empty($text['fields'][$key]['options'])) { $text['fields'][$key]['options'] = self::clean_textarea($text['fields'][$key]['options']); } if (empty($field['options'])) { $temp = sprintf(__('Select options are required for the %s field.', 'si-contact-form'), $field['label']); add_settings_error('fscf_field_settings', 'missing-options', $temp); } } // If date type field, check format of default (if any) if ('date' == $field['type'] && '' != $field['default']) { if ($field['default'] != '[today]' && !FSCF_Process::validate_date($field['default'], self::$current_form)) { $cal_date_array = array('mm/dd/yyyy' => esc_html(__('mm/dd/yyyy', 'si-contact-form')), 'dd/mm/yyyy' => esc_html(__('dd/mm/yyyy', 'si-contact-form')), 'mm-dd-yyyy' => esc_html(__('mm-dd-yyyy', 'si-contact-form')), 'dd-mm-yyyy' => esc_html(__('dd-mm-yyyy', 'si-contact-form')), 'mm.dd.yyyy' => esc_html(__('mm.dd.yyyy', 'si-contact-form')), 'dd.mm.yyyy' => esc_html(__('dd.mm.yyyy', 'si-contact-form')), 'yyyy/mm/dd' => esc_html(__('yyyy/mm/dd', 'si-contact-form')), 'yyyy-mm-dd' => esc_html(__('yyyy-mm-dd', 'si-contact-form')), 'yyyy.mm.dd' => esc_html(__('yyyy.mm.dd', 'si-contact-form'))); $temp = sprintf(__('Default date for %s is not correctly formatted. Format should be %s.', 'si-contact-form'), $field['label'], $cal_date_array[$text['date_format']]); add_settings_error('fscf_field_settings', 'invalid-date', $temp); } } } // end foreach (Process fields) $text = self::vcita_update_details($text); FSCF_Util::unencode_html($text); // Update the query args if necessary if (!isset($_POST['ctf_action']) && isset($_REQUEST['_wp_http_referer'])) { // Set the current tab in _wp_http_referer so that we go there after the save $wp_referer = remove_query_arg('fscf_tab', $_REQUEST['_wp_http_referer']); $wp_referer = add_query_arg('fscf_tab', $_POST['current_tab'], $wp_referer); if (isset($text['akismet_check'])) { // Request Akismet check on page reload $wp_referer = add_query_arg('akismet_check', 'true', $wp_referer); unset($text['akismet_check']); // Don't save this in database } else { $wp_referer = remove_query_arg('akismet_check', $wp_referer); } $_REQUEST['_wp_http_referer'] = $wp_referer; } return $text; }