'', 'redirect' => '', 'hidden' => '', 'email_to' => '', ), $atts)); // Verify form number self::$global_options = SWEETCF_Utils::get_global_options(); self::$form_id_num = '1'; if (isset($form) && is_numeric($form)) { self::$form_id_num = (int) $form; } else { echo __('Contact Form Shortcode Error: Invalid form number in shortcode.', 'sweetcontact'); return; } $frm_id = self::$form_id_num; // Get the form options self::$form_options = SWEETCF_Utils::get_form_options(self::$form_id_num, false); // Don't use defaults if it doesn't exist if (!self::$form_options) { // Form does not exist in options table // Display error message and return echo sprintf(__('Contact Form Shortcode Error: Form %s does not exist', 'sweetcontact'), self::$form_id_num); return; } // Update some language // The update_lang function receives the array by reference, so it can be changed SWEETCF_Utils::update_lang(self::$form_options); // Store shortcode atts // http://sweetcaptcha.com/shortcode-options if (self::$global_options['enable_php_sessions'] == 'true') { // this feature only works when PHP sessions are enabled $_SESSION["fsc_shortcode_redirect_$frm_id"] = $redirect; $_SESSION["fsc_shortcode_hidden_$frm_id"] = $hidden; $_SESSION["fsc_shortcode_email_to_$frm_id"] = $email_to; } else { if (!empty($redirect) || !empty($hidden) || !empty($email_to)) { // trying to use shorcode attributes with the required PHP sessions setting turn off // Display error message and return echo __('Contact Form Shortcode Error: Using shorcode attributes requires the PHP sessions setting to be enabled on the Advanced tab in form settings.', 'sweetcontact'); return; } } self::$form_action_url = self::get_form_action_url(); // initialize vars self::$contact_error = 0; // Save parameters from query string, if any self::get_query_parms(); // initialize external css if (self::$form_options['external_style'] == 'true') { self::get_ext_css(); } // Has a preview been selected? $preview = ( isset($_POST['ctf_action']) && __('Preview Form', 'sweetcontact') == $_POST['ctf_action'] ) ? true : false; //if (is_admin() && $preview && self::$form_options['external_style'] == 'true') { self::external_style_head(); } self::$req_field_ind = ( self::$form_options['req_field_indicator_enable'] == 'true' ) ? '' . self::$form_options['req_field_indicator'] . '' : ''; // See if a form has been processed, and if so, if there were errors if (SWEETCF_Process::$form_processed && SWEETCF_Process::$form_id_num == self::$form_id_num && empty(SWEETCF_Process::$form_errors)) { // Form was processed and has no errors--display thank you message $string = self::display_thank_you(); } else { if (!isset(self::$add_date_js)) { self::$add_date_js_array = array(); self::$add_date_js = ''; } if (!empty(SWEETCF_Process::$form_errors) && SWEETCF_Process::$form_id_num == self::$form_id_num) { // The form was processed, but had errors if (!empty(SWEETCF_Process::$form_data)) { // If this is not true, there is an internal error... self::$form_content = array_merge(self::$form_content, SWEETCF_Process::$form_data); self::$form_errors = array_merge(self::$form_errors, SWEETCF_Process::$form_errors); // XXX later, improve variable usage for error tracking? self::$contact_error = true; } } // ***** Display the Form ***** self::$placeholder = 0; $string = "\n\n
\n" . self::$form_options['welcome']; $string = self::display_form($string); } return($string); } static function get_this_css($tag) { // returns the correct css, inline or external css return $this_style = ( self::$form_options['external_style'] == 'true' ) ? 'class="' . self::$ext_css[$tag] . '"' : self::convert_css(self::$form_options[$tag]); } static function get_ext_css() { // external css class names self::$ext_css = array( // Alignment DIVs 'form_style' => 'swcf-div-form', // Form DIV, how wide is the form DIV 'left_box_style' => 'swcf-div-left-box', // left box DIV, container for vcita 'right_box_style' => 'swcf-div-right-box', // right box DIV, container for vcita 'clear_style' => 'swcf-div-clear', // clear both 'field_left_style' => 'swcf-div-field-left', // field left 'field_prefollow_style' => 'swcf-div-field-prefollow', // field prefollow 'field_follow_style' => 'swcf-div-field-follow', // field follow 'title_style' => 'swcf-div-label', // Input labels alignment DIV 'field_div_style' => 'swcf-div-field', // Input fields alignment DIV 'captcha_div_style_sm' => 'swcf-div-captcha-sm', // Small CAPTCHA DIV 'captcha_div_style_m' => 'swcf-div-captcha-m', // Large CAPTCHA DIV 'captcha_image_style' => 'swcf-image-captcha', // CAPTCHA alignment 'captcha_reload_image_style' => 'swcf-image-captcha-refresh', // CAPTCHA refresh image alignment 'submit_div_style' => 'swcf-div-submit', // Submit DIV 'border_style' => 'swcf-fieldset', // style of the fieldset box (if enabled) // Styles of labels, fields and text 'required_style' => 'swcf-required-indicator', // required field indicator 'required_text_style' => 'swcf-required-text', // required field text 'hint_style' => 'swcf-hint-text', // small text hints like file types 'error_style' => 'swcf-div-error', // Input validation messages 'redirect_style' => 'swcf-div-redirecting', // Redirecting message 'fieldset_style' => 'swcf-fieldset-field', // style of the fieldset box (for a field) 'label_style' => 'swcf-label', // Field labels 'option_label_style' => 'swcf-option-label', // Options labels 'field_style' => 'swcf-input-text', // Input text fields 'captcha_input_style' => 'swcf-input-captcha', // CAPTCHA input field 'textarea_style' => 'swcf-input-textarea', // Input Textarea 'select_style' => 'swcf-input-select', // Input Select 'checkbox_style' => 'swcf-input-checkbox', // Input checkbox 'radio_style' => 'swcf-input-radio', // Input radio 'button_style' => 'swcf-button-submit', // Submit button 'reset_style' => 'swcf-button-reset', // Reset button 'powered_by_style' => 'swcf-powered-by', // the "powered by" link ); } static function get_honeypot_slugs($fields) { // filter a list of field names that are not currently used on the form $decoy_fields = array('address', 'suite', 'company', 'phone', 'title', 'city', 'state', 'fax', 'newsletter', 'webites', 'zipcode', 'address2', 'firstname', 'lastname', 'birthday'); if ($fields && is_array($fields)) { foreach ($decoy_fields as $index => $decoy) { if (isset($fields[$decoy])) { unset($decoy_fields[$index]); } } } sort($decoy_fields); return $decoy_fields; } static function get_todays_honeypot_slug($fields) { // find a decoy field name that is not currently used on the form, change it each day of the week // TODO $decoy_fields = self::get_honeypot_slugs($fields); $max = count($decoy_fields); if ($max > 5) { $index = date('w'); } else if ($max > 0) { $index = 0; } else { return 'email456'; } return $decoy_fields[$index]; } static function display_form($string) { // Build the code to display the form in $string and return it. The form code will be appended to $string and returned global $captcha_path_cf; // used by secureimage.php $captcha_path_cf = SWCF_CAPTCHA_PATH; // Set up the styles for the form self::$style['hint'] = self::convert_css(self::$form_options['hint_style']); self::$style['textarea'] = self::convert_css(self::$form_options['textarea_style']); self::$style['checkbox'] = self::convert_css(self::$form_options['checkbox_style']); self::$style['option_label'] = self::convert_css(self::$form_options['option_label_style']); // option label self::$style['label'] = self::convert_css(self::$form_options['label_style']); // label self::$style['form'] = self::convert_css(self::$form_options['form_style']); self::$style['border'] = self::convert_css(self::$form_options['border_style']); self::$style['fieldset'] = self::convert_css(self::$form_options['fieldset_style']); self::$style['select'] = self::convert_css(self::$form_options['select_style']); self::$style['title'] = self::convert_css(self::$form_options['title_style']); self::$style['field'] = self::convert_css(self::$form_options['field_style']); // text fields self::$style['field_div'] = self::convert_css(self::$form_options['field_div_style']); self::$style['error'] = self::convert_css(self::$form_options['error_style']); self::$style['required'] = self::convert_css(self::$form_options['required_style']); self::$style['required_text'] = self::convert_css(self::$form_options['required_text_style']); self::$style['submit_div'] = self::convert_css(self::$form_options['submit_div_style']); self::$style['submit'] = self::convert_css(self::$form_options['button_style']); self::$style['reset'] = self::convert_css(self::$form_options['reset_style']); self::$aria_required = ' aria-required="true" '; $hidden = "\n"; if (self::$contact_error) { // this is for some people who hide the form in a div, if there are validation errors, unhide it self::$form_options['form_style'] = str_replace('display: none;', '', self::$form_options['form_style']); } $string .= '