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;
 }
Example #2
0
 static function get_query_parms()
 {
     // Check for query arguements, and store them in self::$form_content
     // If nothing is set by query, put in the default, if one exists
     global $fscf_special_slugs;
     // List of reserve slug names
     // initialize vars
     self::$have_attach = '';
     // Get any field values from query parms
     // Get special fields
     // $special_slugs = array( 'f_name', 'm_name', 'mi_name', 'l_name', 'email2', 'mailto_id', 'subject_id' );
     foreach ($fscf_special_slugs as $fld_name) {
         self::$form_content[$fld_name] = self::get_var(self::$form_id_num, $fld_name);
     }
     $default = self::$form_options['fields']['0']['default'];
     // name field
     $placeholder = self::$form_options['fields']['0']['placeholder'];
     if (self::$form_options['name_format'] != 'name' && $default != '' && $placeholder != 'true') {
         if (self::$form_options['name_format'] == 'first_last') {
             // find the true default for first, last only
             // is there xx==xx
             if (!preg_match('/^(.*)(==)(.*)$/', $default, $matches)) {
                 $default = 'First Name==Last Name';
             }
             // default to proper format
             if (preg_match('/^(.*)(==)(.*)$/', $default, $matches)) {
                 if (self::$form_content['f_name'] == '') {
                     self::$form_content['f_name'] = $matches[1];
                 }
                 if (self::$form_content['l_name'] == '') {
                     self::$form_content['l_name'] = $matches[3];
                 }
             }
         } else {
             if (self::$form_options['name_format'] == 'first_middle_last') {
                 // find the true default for first, middle, last
                 // is there xx==xx==xx
                 if (!preg_match('/^(.*)(==)(.*)(==)(.*)$/', $default, $matches)) {
                     $default = 'First Name==Middle Name==Last Name';
                 }
                 // default to proper format
                 if (preg_match('/^(.*)(==)(.*)(==)(.*)$/', $default, $matches)) {
                     if (self::$form_content['f_name'] == '') {
                         self::$form_content['f_name'] = $matches[1];
                     }
                     if (self::$form_content['m_name'] == '') {
                         self::$form_content['m_name'] = $matches[3];
                     }
                     if (self::$form_content['l_name'] == '') {
                         self::$form_content['l_name'] = $matches[5];
                     }
                 }
             } else {
                 if (self::$form_options['name_format'] == 'first_middle_i_last') {
                     // find the true default for first, middle initial, last
                     // is there xx==xx==xx
                     if (!preg_match('/^(.*)(==)(.*)(==)(.*)$/', $default, $matches)) {
                         $default = 'First Name==Middle Initial==Last Name';
                     }
                     // default to proper format
                     if (preg_match('/^(.*)(==)(.*)(==)(.*)$/', $default, $matches)) {
                         if (self::$form_content['f_name'] == '') {
                             self::$form_content['f_name'] = $matches[1];
                         }
                         if (self::$form_content['mi_name'] == '') {
                             self::$form_content['mi_name'] = $matches[3];
                         }
                         if (self::$form_content['l_name'] == '') {
                             self::$form_content['l_name'] = $matches[5];
                         }
                     }
                 }
             }
         }
     }
     // XXX Might need to check for English standard field names, e.g. 'name', as well as the actual field name,
     // which might be translated.  If so, set the field name element to the entry for uame, and unset the name element
     // Get regular fields
     foreach (self::$form_options['fields'] as $key => $field) {
         if ('true' == $field['disable']) {
             continue;
         }
         $fld_name = $field['slug'];
         switch ($field['type']) {
             case 'time':
                 $vars = array();
                 $vars['h'] = self::get_var(self::$form_id_num, $fld_name . '_h');
                 $vars['m'] = self::get_var(self::$form_id_num, $fld_name . '_m');
                 $vars['ap'] = self::get_var(self::$form_id_num, $fld_name . '_ap');
                 self::$form_content[$fld_name] = $vars;
                 // XXX need to add use of default for time as "xx:xx am/pm"
                 break;
             case 'select':
             case 'select-multiple':
             case 'checkbox-multiple':
                 // Checkbox and radio are handled in the default case below
                 $opts_array = explode("\n", $field['options']);
                 $selected = array();
                 if ('select-multiple' == $field['type'] || 'checkbox-multiple' == $field['type']) {
                     $opt_cnt = 1;
                     foreach ($opts_array as $opt) {
                         $sel = self::get_var(self::$form_id_num, $fld_name . '_' . $opt_cnt);
                         if ('1' == $sel) {
                             $selected[] = $opt_cnt;
                         }
                         $opt_cnt++;
                     }
                 }
                 if (0 == count($selected)) {
                     // see if a single option was specified
                     $ind = self::get_var(self::$form_id_num, $fld_name);
                     if (is_numeric($ind) && isset($opts_array[+$ind - 1])) {
                         // XXX to do: it would be nice to allow query input of key # or opt value
                         $selected[] = $ind;
                     } else {
                         if ('' != $field['default']) {
                             // Get the value from the default setting
                             if (!false == strpos($field['default'], ',')) {
                                 // Parse a comma delimited option list
                                 $olist = explode(',', $field['default']);
                                 foreach ($olist as $opt) {
                                     if (is_numeric($opt) && isset($opts_array[+$opt - 1])) {
                                         $selected[] = $opt;
                                     }
                                 }
                             } else {
                                 if (is_numeric($field['default']) && isset($opts_array[+$field['default'] - 1])) {
                                     $selected[] = $field['default'];
                                 }
                             }
                         }
                     }
                 }
                 self::$form_content[$fld_name] = $selected;
                 break;
             case 'attachment':
                 self::$have_attach = 'enctype="multipart/form-data" ';
                 // for <form post
                 self::$form_content[$fld_name] = self::get_var(self::$form_id_num, $fld_name);
                 // There is no default value for an attachment field
                 break;
             case 'fieldset':
             case 'fieldset-close':
             case 'password':
                 break;
             case 'date':
                 // check to be sure that query or default date is a valid date, or do not use it
                 $new_date = self::get_var(self::$form_id_num, $fld_name);
                 if ('' != $new_date & FSCF_Process::validate_date($new_date, self::$form_id_num)) {
                     self::$form_content[$fld_name] = $new_date;
                 }
                 // XXX Consider adding an error or warning message if date field query parm is invalid
                 if (empty(self::$form_content[$fld_name]) && '' != $field['default'] && FSCF_Process::validate_date($field['default'], self::$form_id_num)) {
                     self::$form_content[$fld_name] = $field['default'];
                 }
                 break;
             default:
                 // Special case: the 'full_name' field has 'name' as the query name
                 if ('full_name' == $fld_name) {
                     self::$form_content[$fld_name] = self::get_var(self::$form_id_num, 'name');
                 } else {
                     self::$form_content[$fld_name] = self::get_var(self::$form_id_num, $fld_name);
                 }
                 // fill in defaults if set
                 if ('' == self::$form_content[$fld_name] && '' != $field['default'] && 'true' != $field['placeholder']) {
                     if ('message' == $fld_name || 'textarea' == $field['type']) {
                         self::$form_content[$fld_name] = str_replace('\\n', "\n", $field['default']);
                     } else {
                         if ('email' == $fld_name && 'false' == self::$form_options['double_email']) {
                             self::$form_content[$fld_name] = $field['default'];
                         } else {
                             if ('email' != $fld_name) {
                                 self::$form_content[$fld_name] = $field['default'];
                             }
                         }
                     }
                 }
         }
         // end switch
     }
     // end foreach
     $default = self::$form_options['fields']['1']['default'];
     // email field
     $placeholder = self::$form_options['fields']['1']['placeholder'];
     if ('true' == self::$form_options['double_email'] && $default != '' && $placeholder != 'true') {
         // find the true default for email, email2
         // is there xx==xx
         if (!preg_match('/^(.*)(==)(.*)(==)(.*)$/', $default, $matches)) {
             $default = 'Email==Re-enter Email';
         }
         // default to proper format
         if (preg_match('/^(.*)(==)(.*)$/', $default, $matches)) {
             if (self::$form_content['email'] == '') {
                 self::$form_content['email'] = $matches[1];
             }
             if (self::$form_content['email2'] == '') {
                 self::$form_content['email2'] = $matches[3];
             }
         }
     }
     return;
 }
Example #3
0
 static function set_tags_array()
 {
     // Set up the list of available tags for email
     self::$av_tags_arr = array();
     // used to show available field tags this form
     self::$av_tags_subj_arr = array();
     // used to show available field tags for this form subject
     // Fields
     foreach (self::$form_options['fields'] as $key => $field) {
         switch ($field['standard']) {
             case FSCF_NAME_FIELD:
                 if ($field['disable'] == 'false') {
                     switch (self::$form_options['name_format']) {
                         case 'name':
                             self::$av_tags_arr[] = 'from_name';
                             break;
                         case 'first_last':
                             self::$av_tags_arr[] = 'first_name';
                             self::$av_tags_arr[] = 'last_name';
                             break;
                         case 'first_middle_i_last':
                             self::$av_tags_arr[] = 'first_name';
                             self::$av_tags_arr[] = 'middle_initial';
                             self::$av_tags_arr[] = 'last_name';
                             break;
                         case 'first_middle_last':
                             self::$av_tags_arr[] = 'first_name';
                             self::$av_tags_arr[] = 'middle_name';
                             self::$av_tags_arr[] = 'last_name';
                             break;
                     }
                 }
                 break;
             case FSCF_EMAIL_FIELD:
                 // email
                 if ($field['disable'] == 'false') {
                     self::$av_tags_arr[] = 'from_email';
                 }
                 break;
             case FSCF_SUBJECT_FIELD:
                 break;
             case FSCF_MESSAGE_FIELD:
                 $msg_key = $key;
                 // this is used below
                 break;
             default:
                 // This is an added field
                 if ($field['type'] != 'fieldset-close' && $field['standard'] < 1) {
                     if ($field['type'] == 'fieldset') {
                     } else {
                         if ($field['type'] == 'attachment' && self::$form_options['php_mailer_enable'] == 'wordpress') {
                             self::$av_tags_arr[] = $field['slug'];
                         } else {
                             // text, textarea, date, password, email, url, hidden, time, select, select-multiple, radio, checkbox, checkbox-multiple
                             self::$av_tags_arr[] = $field['slug'];
                         }
                     }
                 }
         }
         // end switch
     }
     // end foreach
     self::$av_tags_subj_arr = self::$av_tags_arr;
     self::$av_tags_arr[] = 'subject';
     if (self::$form_options['fields'][$msg_key]['disable'] == 'false') {
         self::$av_tags_arr[] = 'message';
     }
     self::$av_tags_arr[] = 'full_message';
     if (function_exists('akismet_verify_key') && self::$form_options['akismet_disable'] == 'false') {
         self::$av_tags_arr[] = 'akismet';
     }
     self::$av_tags_arr[] = 'date_time';
     self::$av_tags_arr[] = 'ip_address';
     self::$av_tags_subj_arr[] = 'form_label';
 }
Example #4
0
 static function email_sent_redirect()
 {
     // displays thank you after email is sent
     // Redirct after email sent?
     self::$redirect_enable = 'false';
     if (self::$form_options['redirect_enable'] == 'true') {
         self::$redirect_enable = 'true';
         $ctf_redirect_url = self::$form_options['redirect_url'];
     }
     // allow shortcode redirect to override options redirect settings
     if (self::$global_options['enable_php_sessions'] == 'true' && $_SESSION['fsc_shortcode_redirect_' . self::$form_id_num] != '') {
         self::$redirect_enable = 'true';
         $ctf_redirect_url = strip_tags($_SESSION['fsc_shortcode_redirect_' . self::$form_id_num]);
     }
     if (self::$redirect_enable == 'true') {
         if ($ctf_redirect_url == '#') {
             // if you put # for the redirect URL it will redirect to the same page the form is on regardless of the page.
             $ctf_redirect_url = self::$form_action_url;
         }
         // filter hook for changing the redirect URL. You could make a function that changes it based on fields
         $ctf_redirect_url = apply_filters('si_contact_redirect_url', $ctf_redirect_url, self::$email_fields, self::$form_data['mailto_id'], self::$form_id_num);
         // redirect query string code
         if (self::$form_options['redirect_query'] == 'true') {
             // build query string
             $query_string = self::export_convert(self::$email_fields, self::$form_options['redirect_rename'], self::$form_options['redirect_ignore'], self::$form_options['redirect_add'], 'query');
             if (!preg_match("/\\?/", $ctf_redirect_url)) {
                 $ctf_redirect_url .= '?' . $query_string;
             } else {
                 $ctf_redirect_url .= '&' . $query_string;
             }
         }
         $ctf_redirect_timeout = absint(self::$form_options['redirect_seconds']);
         // time in seconds to wait before loading another Web page
         if ($ctf_redirect_timeout == 0) {
             // use wp_redirect when timeout seconds is 0.
             // So now if you set the timeout to 0 seconds, then post the form, it gets instantly redirected to the redirect URL
             // and you are responsible to display the "your message has been sent, thank you" message there.
             wp_redirect($ctf_redirect_url);
             exit;
         }
         // meta refresh page timer feature
         // allows some seconds to to display the "your message has been sent, thank you" message.
         self::$meta_string = "<meta http-equiv=\"refresh\" content=\"{$ctf_redirect_timeout};URL={$ctf_redirect_url}\">\n";
         if (is_admin()) {
             add_action('admin_head', 'FSCF_Process::meta_refresh', 1);
         } else {
             add_action('wp_head', 'FSCF_Process::meta_refresh', 1);
         }
     }
     // end if (self::$redirect_enable == 'true')
 }