0) ) ? intval($email_options['wp_user']) : 1; // By default - admin
if ( $wp_user ) {
$user = $wpdb->get_row("SELECT user_login, user_email FROM $wpdb->users WHERE ID='$wp_user'", 0);
$contacts_list = $user->user_email;
$wp_user_name = $user->user_login;
}
}
if (SWEETCF_Utils::validate_email($contacts_list)) {
$contacts[] = array('CONTACT' => $wp_user_name, 'EMAIL' => $contacts_list);
}
return($contacts);
}
static function get_form_num() {
// Set the number of the current form. Form 1 cannot be deleted, so we can use it as the default
self::$current_form = 1; // This is the default
$form_num_default = 1;
if (isset($_REQUEST['swcf_form'])) {
self::$current_form = $_REQUEST['swcf_form'];
} elseif (isset($_REQUEST['_wp_http_referer'])) {
$parts = explode('swcf_form=', $_REQUEST['_wp_http_referer']);
if (count($parts) == 2) {
self::$current_form = absint($parts[1]);
}
}
if (!is_numeric(self::$current_form)) {
echo '
';
echo __('Internal Error: Invalid form number.', 'sweetcontact');
echo "
\n";
self::$current_form = $form_num_default;
}
self::$form_option_name = "sweetcontact_form" . self::$current_form;
// Check for the current tab number
self::$current_tab = (isset($_REQUEST['swcf_tab']) && is_numeric($_REQUEST['swcf_tab'])) ? absint($_REQUEST['swcf_tab']) : 1;
}
static function register_options_page() {
// Add link to Admin Menu
//$page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '', $position = null )
add_menu_page(
__('sweetContact', 'sweetcontact'), // Page title
__('sweetContact', 'sweetcontact'), // Menu title
'manage_options', // Capability
'sweetcontact', // menu_slug
'SWEETCF_Options::display_options', // function
SWCF_URL . '/includes/images/menu-icon.png');
}
static function get_options() {
if (!isset(self::$form_defaults)) {self::$form_defaults = SWEETCF_Utils::set_defaults(); }
if (!self::$global_options) { self::$global_options = SWEETCF_Utils::get_global_options(); }
if (!self::$form_options) { self::$form_options = SWEETCF_Utils::get_form_options(self::$current_form, true); }
// See if the form name has changed--if so, update it in the list
if (( self::$global_options['form_list'][self::$current_form] <> self::$form_options['form_name'] ) && self::$form_options['form_name'] <> "") {
self::$global_options['form_list'][self::$current_form] = self::$form_options['form_name'];
update_option('sweetcontact_global', self::$global_options);
}
if (count(self::$form_options) < count(self::$form_defaults)) {
// add missing elements from the default form options array
self::$form_options = array_merge(self::$form_defaults, self::$form_options);
}
}
static function unload_options() {
// Forces the reload of global and form options. Called by SWEETCF_Action::restore_settings()
self::$global_options = false;
self::$form_options = false;
}
static function initialize_options() {
self::get_form_num(); // Get the current form
// Register settings sections
add_settings_section('swcf_name_settings', '1. '.__('Name your sweetContact form', 'sweetcontact'), 'SWEETCF_Options::settings_name_callback', 'tab_page1');
add_settings_section('swcf_field_settings', '2. '.__('Add fields to your form', 'sweetcontact'), 'SWEETCF_Options::settings_field_callback', 'tab_page2');
add_settings_section('swcf_email_settings', '3. '.__('Configure Mail', 'sweetcontact'), 'SWEETCF_Options::settings_email_callback', 'tab_page3');
add_settings_section('swcf_design_settings', '4. '.__('Configure the sweetContact form design', 'sweetcontact'), 'SWEETCF_Options::settings_design_callback', 'tab_page4');
add_settings_section('swcf_thankyou_settings', '5. '.__('Configure the message the user will get after `Submit`', 'sweetcontact'), 'SWEETCF_Options::settings_thankyou_callback', 'tab_page5');
//add_settings_section('swcf_style_settings', __('Style Settings', 'sweetcontact'), 'SWEETCF_Options::style_settings_callback', 'tab_page1');
//add_settings_section('swcf_captcha_settings', '6. '.__('Configure security on your form', 'sweetcontact'), 'SWEETCF_Options::settings_captcha_callback', 'tab_page6');
add_settings_section(
'swcf_basic_settings', // ID used to identify this section and with which to register options
'6. '.__('Add your new sweetContact form to the blog', 'sweetcontact'), // Title to be displayed on the administration page
'SWEETCF_Options::settings_basic_callback', 'tab_page6'
);
register_setting('sw_contact_options', 'sweetcontact_form' . self::$current_form, 'SWEETCF_Options::validate');
}
static function display_options() {
//echo 'initSweetCaptchaInstance count: '; var_export($_REQUEST['initSweetCaptchaInstance']);echo ' ';
//var_export($_REQUEST['submit_register_form']);
$form_num = self::$current_form;
$tab_names = array(
__('Add fields to your form', 'sweetcontact'),
__('Configure Mail', 'sweetcontact'),
__('Configure the sweetContact form design', 'sweetcontact'),
__('Configure the message the user will get after `Submit`', 'sweetcontact'),
__('Configure security on your form', 'sweetcontact'),
__('Add your new sweetContact form to the blog', 'sweetcontact'),
);
$num_tabs = count($tab_names);
// Process ctf_actions, if any
if (!empty($_POST['ctf_action'])) { SWEETCF_Action::do_ctf_action(); }
self::get_options(); // Load the options into the options array
SWEETCF_Utils::update_lang(self::$form_options);
SWEETCF_Utils::update_lang(self::$form_defaults);
self::set_fld_array();
// Create a header in the default WordPress 'wrap' container
?>
';
?>
self::$current_form));
} else { ?>
';
$option_email_to = self::$global_options['email']['email_to'];//self::$form_options['email_to'];
$option_custom_email = isset(self::$global_options['email']['custom_email']) ? trim(self::$global_options['email']['custom_email']) : '';
self::$contacts = (self::$contacts) ? self::$contacts : self::get_contact_list();
//echo 'contacts: '; var_export(self::$contacts); echo '';
if ( empty(self::$contacts) ) {
$ctf_contacts_error_message = ''.__('ERROR: ').''.__('You must enter a valid email address in step 3 If you choose a WordPress user email, make sure its entered under the user email.', 'sweetcontact');
}
if ( empty($ctf_contacts_error_message) ) {
if ( $option_email_to == 'custom' ) {
if ( ! SWEETCF_Utils::validate_email($option_custom_email) ) {
$ctf_contacts_error_message = __('ERROR: Misconfigured "Email To" address', 'sweetcontact') . ': ' . __(' Regular email address not valid', 'sweetcontact');
}
}
}
if ( $ctf_contacts_error_message ) {
echo "
$ctf_contacts_error_message
\n";
echo "
$ctf_contacts_error_message
\n";
}
if ( ! function_exists('mail') ) {
echo '
' . __('Warning: Your web host has the mail() function disabled. PHP cannot send email.', 'sweetcontact');
echo ' ' . __('Have them fix it. Or you can install the "WP Mail SMTP" plugin and configure it to use SMTP.', 'sweetcontact') . '
'false',
'placeholder' => 'false',
);
$placeholder_error = 0;
$name_format_error = 0;
$email_format_error = 0;
$dup_field_error = 0;
$field_names = array();
$fields_count = count(self::$form_options['fields']);
foreach (self::$form_options['fields'] as $key => $field) {
$field_opt_name = self::$form_option_name . '[fields][' . $key . ']';
// fill in any missing field options defaults
foreach ($field_opt_defaults as $dfkey => $dfval) {
if (!isset($field[$dfkey]) || empty($field[$dfkey]))
$field[$dfkey] = $dfval;
}
?>
' . self::$new_field_added . '
' . "\n";
self::$new_field_key = $key + 1;
}
// warn if placeholder is missing the Default text
if ($field['placeholder'] == 'true' && $field['default'] == '') {
if (!$placeholder_error) {
echo '
';
echo __('Caution: "Default as placeholder" setting requires "Default" setting to be filled in. Correct this on the Fields tab and click Save Changes', 'sweetcontact');
echo "
\n";
}
echo '
' . __('Caution: "Default as placeholder" setting requires "Default" setting to be filled in. Correct this in the field details and click Save Changes', 'sweetcontact') . '
' . "\n";
$placeholder_error = 1;
}
// warn if name default not in proper format
if (SWCF_NAME_FIELD == $field['standard']) {
$name_format_array = array(
'name' => __('Name', 'sweetcontact'),
'first_last' => __('First Name, Last Name', 'sweetcontact'),
'first_middle_i_last' => __('First Name, Middle Initial, Last Name', 'sweetcontact'),
'first_middle_last' => __('First Name, Middle Name, Last Name', 'sweetcontact'),
);
if ($field['default'] != '' && self::$form_options['name_format'] == 'first_last') {
if (!preg_match('/^(.*)(==)(.*)$/', $field['default'], $matches)) { $name_format_error = 'First Name==Last Name'; }
} else if ($field['default'] != '' && self::$form_options['name_format'] == 'first_middle_last') {
if (!preg_match('/^(.*)(==)(.*)(==)(.*)$/', $field['default'], $matches)) { $name_format_error = 'First Name==Middle Name==Last Name'; }
} else if ($field['default'] != '' && self::$form_options['name_format'] == 'first_middle_i_last') {
if (!preg_match('/^(.*)(==)(.*)(==)(.*)$/', $field['default'], $matches)) { $name_format_error = 'First Name==Middle Initial==Last Name'; }
}
if ($name_format_error) {
$this_name_format = $name_format_array[self::$form_options['name_format']];
echo '
';
echo sprintf(__('Caution: Name field format "%s" requires the "Default" setting to be in this example format: %s. Separate words with == separators, or empty the "Default" setting. Correct this on the Fields tab and click Save Changes', 'sweetcontact'), $this_name_format, $name_format_error);
echo "
\n";
echo '
' . sprintf(__('Caution: Name field format "%s" requires the "Default" setting to be in this example format: %s. Separate words with == separators, or empty the "Default" setting. Correct this in the field details and click Save Changes', 'sweetcontact'), $this_name_format, $name_format_error) . '
' . "\n";
}
}
// warn if double email default not in proper format
if (SWCF_EMAIL_FIELD == $field['standard'] && 'true' == self::$form_options['double_email'] && $field['default'] != '') {
if (!preg_match('/^(.*)(==)(.*)$/', $field['default'], $matches)) {
echo '
';
echo __('Caution: When "Enable double email entry" setting is enabled, the "Default" setting should be in this example format: Email==Re-enter Email. Separate words with == separators, or empty the "Default" setting. Correct this on the Fields tab and click Save Changes', 'sweetcontact');
echo "
\n";
echo '
' . __('Caution: "When Enable double email entry" setting is enabled, the "Default" setting should be in this example format: Email==Re-enter Email. Separate words with == separators, or empty the "Default" setting. Correct this in the field details and click Save Changes', 'sweetcontact') . '
' . "\n";
}
}
// Make sure field names are unique
if (in_array($field['label'], $field_names)) {
// We have a duplicate field label, display an error message
if (!$dup_field_error) {
echo '
';
echo __('Caution: Duplicate field label. Now you must change the field label on the Fields tab and click Save Changes', 'sweetcontact');
echo "
\n";
}
echo '
' . __('Caution: Duplicate field label. Change the field label and click Save Changes', 'sweetcontact') . '
self::$global_options['enable_php_sessions']) {
self::$global_options['enable_php_sessions'] = $php_sessions;
}
if ( isset($_POST['email_to']) && isset($_POST['wp_user']) && isset($_POST['custom_email']) ) {
self::$global_options['email']['email_to'] = $_POST['email_to'];
self::$global_options['email']['wp_user'] = $_POST['wp_user'];
self::$global_options['email']['custom_email'] = $_POST['custom_email'];
}
update_option('sweetcontact_global', self::$global_options);
SWEETCF_Utils::trim_array($text); // Trim trailing spaces
// Special processing for certain form fields
//if ( !isset($text['email_to']) || ('' == $text['email_to']) ) { $text['email_to'] = self::$form_defaults['email_to']; } // use default if empty
$text['redirect_seconds'] = ( isset($text['redirect_seconds']) && is_numeric($text['redirect_seconds']) && ($text['redirect_seconds'] < 61) ) ? absint($text['redirect_seconds']) : self::$form_defaults['redirect_seconds'];
$text['redirect_url'] = ( isset($text['redirect_url']) && !empty($text['redirect_url']) ) ? $text['redirect_url'] : self::$form_defaults['redirect_url']; // use default if empty
if ( !isset($text['cal_start_day']) || !preg_match('/^[0-6]?$/', $text['cal_start_day'])) {
$text['cal_start_day'] = self::$form_defaults['cal_start_day'];
}
$text['attach_types'] = (isset($text['attach_types'])) ? str_replace('.', '', $text['attach_types']) : '';
if ( !isset($text['attach_size']) || ('' == $text['attach_size']) || !preg_match('/^([[0-9.]+)([kKmM]?[bB])?$/', $text['attach_size'])) {
$text['attach_size'] = self::$form_defaults['attach_size'];
}
if ( !isset($text['auto_respond_from_name']) || ('' == $text['auto_respond_from_name']) ) {
$text['auto_respond_from_name'] = self::$form_defaults['auto_respond_from_name']; // use default if empty
}
if ( !isset($text['auto_respond_from_email']) || ('' == $text['auto_respond_from_email']) || !SWEETCF_Utils::validate_email($text['auto_respond_from_email'])) {
$text['auto_respond_from_email'] = self::$form_defaults['auto_respond_from_email']; // use default if empty
}
if ( !isset($text['auto_respond_reply_to']) || ($text['auto_respond_reply_to'] == '') || !SWEETCF_Utils::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 = SWEETCF_Utils::set_style_defaults();
}
foreach (self::$style_defaults as $key => $val) {
if (!isset($text[$key]) || empty($text[$key])) { $text[$key] = $val; }
}
// Do we need to reset all styles top this form?
if (isset($_POST['swcf_reset_styles'])) { // reset styles feature
$text = SWEETCF_Action::copy_styles(self::$form_defaults, $text);
}
// 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', 'captcha_enable',
'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', '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',
);
// 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');
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 = $swcf_special_slugs;
// The $special_slugs list is also used in SWEETCF_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'
);
foreach ($text['fields'] as $key => $field) {
$field['type'] = isset($field['type']) ? $field['type'] : 'text';
if (isset($field['delete']) && "true" == $field['delete']) {
unset($text['fields'][$key]); // Delete the field
} 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; // allow html
} 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', 'sweetcontact'), $key);
$temp = sprintf(__('Field label cannot be blank. Label set to "Field %s". To delete a field, use the delete option.', 'sweetcontact'), $key);
add_settings_error('swcf_field_settings', 'missing-label', $temp);
}
// Sanitize the slug
$slug_changed = false;
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, SWCF_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, SWCF_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, SWCF_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, SWCF_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.', 'sweetcontact'), $field['label']);
add_settings_error('swcf_field_settings', 'missing-options', $temp);
}
}
// If date type field, check format of default (if any)
if ( ('date' == $field['type']) && ('' != $field['default']) ) {
if (!SWEETCF_Process::validate_date($field['default'], self::$current_form)) {
$cal_date_array = array(
'mm/dd/yyyy' => esc_html(__('mm/dd/yyyy', 'sweetcontact')),
'dd/mm/yyyy' => esc_html(__('dd/mm/yyyy', 'sweetcontact')),
'mm-dd-yyyy' => esc_html(__('mm-dd-yyyy', 'sweetcontact')),
'dd-mm-yyyy' => esc_html(__('dd-mm-yyyy', 'sweetcontact')),
'mm.dd.yyyy' => esc_html(__('mm.dd.yyyy', 'sweetcontact')),
'dd.mm.yyyy' => esc_html(__('dd.mm.yyyy', 'sweetcontact')),
'yyyy/mm/dd' => esc_html(__('yyyy/mm/dd', 'sweetcontact')),
'yyyy-mm-dd' => esc_html(__('yyyy-mm-dd', 'sweetcontact')),
'yyyy.mm.dd' => esc_html(__('yyyy.mm.dd', 'sweetcontact')),
);
$temp = sprintf(__('Default date for %s is not correctly formatted. Format should be %s.', 'sweetcontact'), $field['label'], $cal_date_array[$text['date_format']]);
add_settings_error('swcf_field_settings', 'invalid-date', $temp);
}
}
}
SWEETCF_Utils::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('swcf_tab', $_REQUEST['_wp_http_referer']);
$wp_referer = add_query_arg('swcf_tab', $_POST['current_tab'], $wp_referer);
$_REQUEST['_wp_http_referer'] = $wp_referer;
}
return( $text );
}
// end function validate($text);
static function check_slug($slug, $slug_list) {
// Checks the slug, and adds a number if necessary to make it unique
// $slug -- the slug to be checked
// $slug_list -- a list of existing slugs
// Returns the new slug
// Duplicates have a two digit number appended to the end to make them unique
// XXX do I neeed any messages about changing the slug?
$numb = preg_match('/\d{2}$/', $slug, $match);
while (in_array($slug, $slug_list)) {
if ($numb) {
$new_numb = sprintf("%02d", substr($slug, strlen($slug) - 2, 2) + 1);
$slug = substr($slug, 0, strlen($slug) - 2) . $new_numb;
} else {
$slug .= '01';
$numb = 1;
}
}
return($slug);
}
static function clean_textarea($data) {
// cleans blank lines and trims gaps from textarea list inputs
// Returns the new data
$new_data = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $data);
$data_array = explode("\n", $new_data);
$new_data = '';
foreach ($data_array as $line) {
$line = trim($line);
if ($line != '') // do not use !empty, or an option '0' is deleted
$new_data .= "$line\n";
}
return trim($new_data);
}
static function set_fld_array() { // Set up the list of available tags for email
self::get_options();
self::$av_fld_arr = array(); // used to show available field tags this form
self::$av_fld_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 SWCF_NAME_FIELD :
if ($field['disable'] == 'false') {
switch (self::$form_options['name_format']) {
case 'name':
self::$av_fld_arr[] = 'from_name';
break;
case 'first_last':
self::$av_fld_arr[] = 'first_name';
self::$av_fld_arr[] = 'last_name';
break;
case 'first_middle_i_last':
self::$av_fld_arr[] = 'first_name';
self::$av_fld_arr[] = 'middle_initial';
self::$av_fld_arr[] = 'last_name';
break;
case 'first_middle_last':
self::$av_fld_arr[] = 'first_name';
self::$av_fld_arr[] = 'middle_name';
self::$av_fld_arr[] = 'last_name';
break;
}
}
break;
case SWCF_EMAIL_FIELD :
// email
self::$autoresp_ok = 1; // used in autoresp settings below
if ($field['disable'] == 'false') {
self::$av_fld_arr[] = 'from_email';
} else {
self::$autoresp_ok = 0;
}
break;
case SWCF_SUBJECT_FIELD :
break;
case SWCF_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_fld_arr[] = $field['slug'];
} else { // text, textarea, date, password, email, url, hidden, time, select, select-multiple, radio, checkbox, checkbox-multiple
self::$av_fld_arr[] = $field['slug'];
if ($field['type'] == 'email') { $autoresp_ok = 1; }
}
}
} // end switch
} // end foreach
self::$av_fld_subj_arr = self::$av_fld_arr;
self::$av_fld_arr[] = 'subject';
if (self::$form_options['fields'][$msg_key]['disable'] == 'false') {
self::$av_fld_arr[] = 'message';
}
self::$av_fld_arr[] = 'full_message';
self::$av_fld_arr[] = 'date_time';
self::$av_fld_arr[] = 'ip_address';
self::$av_fld_subj_arr[] = 'form_label';
}
static function add_field() {
check_admin_referer('sw_contact_options-options', 'fs_options');
self::get_options();
self::$form_options['fields'][] = SWEETCF_Utils::$field_defaults;
self::$new_field_added = __('A new field has been added. Now you must edit the field name and details, then click Save Changes.', 'sweetcontact');
echo '
' . self::$new_field_added . '
';
}
static function add_form() {
// Add a new form
check_admin_referer('sw_contact_options-options', 'fs_options');
if (!self::$global_options) { self::$global_options = SWEETCF_Utils::get_global_options(); }
// Find the next form number. When forms are deleted, their form number is NOT reused
self::$global_options['form_list'][self::$current_form] = __('New Form', 'sweetcontact');
// Highest form ID (used to assign ID to new form)
// When forms are deleted, the remaining forms are NOT renumberd, so max_form_num might be greater than the number of existing forms
// recalibrate max_form_num to the highest form number (not count)
ksort(self::$global_options['form_list']);
self::$global_options['max_form_num'] = max(array_keys(self::$global_options['form_list']));
update_option('sweetcontact_global', self::$global_options);
echo '
' . sprintf(__('Form %d has been added.', 'sweetcontact'), self::$current_form) . '
';
return;
}
static function delete_form() { // Delete the current form
check_admin_referer('sw_contact_options-options', 'fs_options');
self::get_options();
if (isset($_POST['form_num']) && is_numeric($_POST['form_num'])) {
$form_num = absint($_POST['form_num']);
$op_name = 'sweetcontact_form' . $form_num;
$result = delete_option($op_name);
if (!$result) {
// Error deleting option
echo '
' . sprintf(__('An error has occured. Form %d could not be deleted.', 'sweetcontact'), $form_num) . '
';
} else {
unset(self::$global_options['form_list'][$form_num]);
// Highest form ID (used to assign ID to new form)
// When forms are deleted, the remaining forms are NOT renumberd, so max_form_num might be greater than
// the number of existing forms
ksort(self::$global_options['form_list']);
self::$global_options['max_form_num'] = max(array_keys(self::$global_options['form_list']));
update_option('sweetcontact_global', self::$global_options);
echo '
' . sprintf(__('Form %d has been deleted.', 'sweetcontact'), $form_num) . '