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 = FSCF_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 .= ' <div id="FSContact' . self::$form_id_num . '" ' . self::get_this_css('form_style') . '>'; $form_attributes = ''; if (!empty(self::$form_options['form_attributes'])) { $form_attributes = self::$form_options['form_attributes'] . ' '; } if (self::$form_options['vcita_scheduling_button'] == 'true' && self::is_vcita_activated()) { $string .= "\n<div " . 'id="fscf_div_left_box' . self::$form_id_num . '" ' . self::get_this_css('left_box_style') . ">"; } $anchor = ''; if (self::$form_options['anchor_enable'] == 'true') { $anchor = '#FSContact' . self::$form_id_num; } $string .= ' <form ' . self::$have_attach . 'action="' . esc_url(self::$form_action_url) . $anchor . '" id="fscf_form' . self::$form_id_num . '" ' . $form_attributes . 'method="post"> '; if (self::$form_options['border_enable'] == 'true') { $string .= '<fieldset id="fscf_form_fieldset' . self::$form_id_num . '" ' . self::get_this_css('border_style') . ">\n"; if (self::$form_options['title_border'] != '') { $string .= '<legend>'; $string .= self::$form_options['title_border']; $string .= "</legend>\n"; } } // check attachment directory $frm_id = self::$form_id_num; // needed for use w/in "" below.. can't use self:: if (self::$have_attach) { self::init_temp_dir(FSCF_ATTACH_DIR); if (self::$form_options['php_mailer_enable'] == 'php') { self::set_form_error("fscf_attach_dir{$frm_id}", __('Attachments are only supported when the Send Email function is set to WordPress. You can find this setting on the contact form settings page.', 'si-contact-form')); } if (!is_dir(FSCF_ATTACH_DIR)) { self::set_form_error("fscf_attach_dir{$frm_id}", __('The temporary folder for the attachment field does not exist.', 'si-contact-form')); } else { if (!is_writable(FSCF_ATTACH_DIR)) { self::set_form_error("fscf_attach_dir{$frm_id}", __('The temporary folder for the attachment field is not writable.', 'si-contact-form')); } else { // delete files over 3 minutes old in the attachment directory // full directory sweep cleanup //self::clean_temp_dir( FSCF_ATTACH_DIR, 3 ); } } } // print input error message if (self::$contact_error) { // There are errors, so print the generic error message $string .= ' <div id="fscf_form_error' . self::$form_id_num . '" ' . self::get_this_css('error_style') . ">\n"; $string .= self::$form_options['error_correct'] != '' ? self::$form_options['error_correct'] : __('Please make corrections below and try again.', 'si-contact-form'); $string .= "\n </div>\n"; // Print errors that appear at the top of the form $string .= self::echo_if_error("fscf_attach_dir{$frm_id}"); $string .= self::echo_if_error('akismet'); } // Get the email-to list self::$contacts = self::get_contact_list(self::$form_id_num, self::$form_options['email_to']); if (empty(self::$contacts)) { // was $ctf_contacts $string .= ' <div id="fscf_form_error_email' . self::$form_id_num . '" ' . self::get_this_css('error_style') . '>' . __('ERROR: Misconfigured email address in options.', 'si-contact-form') . "\n </div>\n"; } if (self::$global_options['enable_php_sessions'] == 'true') { // this feature only works when PHP sessions are enabled if (!empty($_SESSION["fsc_shortcode_hidden_{$frm_id}"])) { $hidden_fields = self::get_hidden_fields(); if (!empty($hidden_fields)) { foreach ($hidden_fields as $key => $value) { $hidden .= "\n" . '<input type="hidden" name="' . esc_attr($key) . '" value="' . esc_attr($value) . '" />' . "\n"; } } } else { unset($_SESSION["fsc_shortcode_hidden_{$frm_id}"]); } } // Add a hidden field if this is the admin preview, so that we return to the preview after submit if (is_admin()) { $hidden .= '<input type="hidden" name="ctf_action" value="' . __('Preview Form', 'si-contact-form') . '" />' . "\n"; } $hidden .= '<input type="hidden" name="fscf_submitted" value="0" />' . "\n"; $hidden .= '<input type="hidden" name="fs_postonce_' . self::$form_id_num . '" value="' . wp_hash(time()) . ',' . time() . '" />' . "\n"; $hidden .= '<input type="hidden" name="si_contact_action" value="send" />' . "\n"; $hidden .= '<input type="hidden" name="form_id" value="' . self::$form_id_num . '" />' . "\n"; if (self::$form_options['req_field_label_enable'] == 'true' && self::$form_options['req_field_indicator_enable'] == 'true') { $string .= "\n" . '<div id="fscf_required' . self::$form_id_num . '">' . "\n"; $string .= ' <span ' . self::get_this_css('required_style') . '>' . self::$form_options['req_field_indicator'] . '</span> <span ' . self::get_this_css('required_text_style') . '>'; $string .= self::$form_options['tooltip_required'] != '' ? self::$form_options['tooltip_required'] : __('indicates required field', 'si-contact-form'); $string .= "</span>\n</div>\n\n"; } // If there are multiple mail-to contacts, display a select form if (count(self::$contacts) > 1) { $string .= '<div id="fscf_div_clear_contact' . self::$form_id_num . '" ' . self::get_this_css('clear_style') . '>' . "\n" . ' <div id="fscf_div_field_contact' . self::$form_id_num . '" ' . self::get_this_css('field_left_style') . '> <div ' . self::get_this_css('title_style') . '> <label ' . self::get_this_css('label_style') . ' for="fscf_mail_to' . self::$form_id_num . '">'; $string .= self::$form_options['title_dept'] != '' ? self::$form_options['title_dept'] : __('Select a contact:', 'si-contact-form'); $string .= self::$req_field_ind . '</label> </div> <div ' . self::get_this_css('field_div_style') . '>' . self::echo_if_error('contact') . ' <select ' . self::get_this_css('select_style') . ' id="fscf_mail_to' . self::$form_id_num . '" name="mailto_id" ' . self::$aria_required . '> '; $string .= ' <option value="">'; $string .= self::$form_options['title_select'] != '' ? esc_html(self::$form_options['title_select']) : esc_html(__('Select', 'si-contact-form')); $string .= "</option>\n"; if (!isset($cid) && '' != self::$form_content['mailto_id']) { $cid = (int) self::$form_content['mailto_id']; } $selected = ''; foreach (self::$contacts as $k => $v) { if (!empty($cid) && $cid == $k) { $selected = ' selected="selected"'; } $string .= ' <option value="' . $k . '"' . $selected . '>' . esc_attr($v['CONTACT']) . "</option>\n"; $selected = ''; } $string .= ' </select> </div> </div> </div> '; } else { $hidden .= '<input type="hidden" name="mailto_id" value="1" />' . "\n"; } $open_fieldset = false; // is a fieldset field open? // A div class="fscf-clear" is used to group a field with any that follow it // $open_div tracks whether this div is currently open $open_div = false; $date_fields = array(); // List of date fields self::$printed_tooltip_filetypes = 0; // ********** Go through all the fields and print them ********** // fill in any missing defaults $field_opt_defaults = array('hide_label' => 'false', 'placeholder' => 'false'); $fields_in_use = array(); foreach (self::$form_options['fields'] as $key => $field) { // fill in any missing field options defaults foreach ($field_opt_defaults as $dfkey => $dfval) { if (!isset($field[$dfkey]) || empty($field[$dfkey])) { $field[$dfkey] = $dfval; } } if ('true' == $field['disable']) { continue; } $fields_in_use[$field['slug']] = 1; if ('true' == $field['follow'] && $open_div) { $string .= ' <div id="fscf_div_follow' . self::$form_id_num . '_' . $key . '" ' . self::get_this_css('field_follow_style') . '>'; } else { if ($open_div) { // close the preceeding div used for grouping $string .= "</div>\n"; $open_div = false; } if ('fieldset' == $field['type'] || 'fieldset-close' == $field['type']) { $string .= "\n" . '<div ' . self::get_this_css('clear_style') . "></div>\n"; } else { $open_div = true; $string .= "\n" . '<div id="fscf_div_clear' . self::$form_id_num . '_' . $key . '" ' . self::get_this_css('clear_style') . '>' . "\n" . ' '; $string .= '<div id="fscf_div_field' . self::$form_id_num . '_' . $key . '" '; // find out if this field preceeds a follow field or vcita enabled (narrow), else it needs to be (wide) if (isset(self::$form_options['fields'][$key + 1]) && self::$form_options['fields'][$key + 1]['follow'] == 'true' || self::$form_options['vcita_scheduling_button'] == 'true' && self::is_vcita_activated()) { $string .= self::get_this_css('field_prefollow_style') . '>'; } else { $string .= self::get_this_css('field_left_style') . '>'; } // wide } } // Display code common to all/most field types if (!in_array($field['type'], array('fieldset', 'fieldset-close', 'hidden'))) { if ($field['notes'] != '') { $string .= "\n" . self::ctf_notes($field['notes']); } if ('checkbox' != $field['type'] && $field['standard'] < 1 && 'false' == $field['hide_label']) { // hiding the label // Standard field labels can be changed in options, so don't print them here // single checkbox labels are printed next to the checkbox $string .= "\n <div " . ' id="fscf_label' . self::$form_id_num . '_' . $key . '" ' . self::get_this_css('title_style') . '> <label '; $string .= $field['label_css'] != '' ? self::convert_css($field['label_css']) : self::get_this_css('label_style'); $string .= ' for="fscf_field' . self::$form_id_num . '_' . $key . '">' . esc_html($field['label']); $string .= 'true' == $field['req'] ? self::$req_field_ind : ''; $string .= "</label>\n </div>"; } else { if ('checkbox' == $field['type'] && $field['standard'] < 1 || 'true' == $field['hide_label']) { // single checkbox keep the div to maintain style left alignment (no label here), or hide label was checked $string .= "\n <div " . ' id="fscf_label' . self::$form_id_num . '_' . $key . '" ' . self::get_this_css('title_style'); $string .= ">\n </div>"; } } self::$aria_required = $field['req'] && 'true' == self::$form_options['aria_required'] ? ' aria-required="true" ' : ''; } switch ($field['type']) { case 'fieldset': if ($open_fieldset) { $string .= "</fieldset>\n"; } if ($field['notes'] != '') { $string .= "\n" . self::ctf_notes($field['notes']); } $string .= "\n<fieldset" . ' id="fscf_fieldset' . self::$form_id_num . '_' . $key . '" '; $string .= $field['label_css'] != '' ? self::convert_css($field['label_css']) : self::get_this_css('fieldset_style'); $string .= '> '; if ('false' == $field['hide_label']) { $string .= ' <legend>' . esc_html($field['label']) . "</legend>\n"; } $open_fieldset = true; break; case 'fieldset-close': if ($open_fieldset) { $string .= "</fieldset>\n"; } $open_fieldset = false; break; case 'hidden': $string .= ' <input type="hidden" name="' . $field['slug'] . '" value="' . esc_attr(self::$form_content[$field['slug']]) . '" />' . "\n"; break; case 'password': $string .= ' <div ' . self::get_this_css('field_div_style') . '>' . self::echo_if_error($field['slug']) . "\n" . ' <input '; $string .= $field['input_css'] != '' ? self::convert_css($field['input_css']) : self::get_this_css('field_style'); $string .= ' type="password" id="fscf_field' . self::$form_id_num . '_' . $key . '" name="' . $field['slug'] . '" value=""' . '" ' . self::$aria_required . ' '; if ($field['max_len'] != '') { $string .= ' maxlength="' . $field['max_len'] . '"'; } if ($field['attributes'] != '') { $string .= ' ' . $field['attributes']; } $string .= " />\n </div>\n"; break; case 'text': case 'email': case 'url': $string .= self::display_field_text($key, $field); break; case 'textarea': $string .= self::display_field_textarea($key, $field); break; case 'select': case 'select-multiple': $string .= self::display_field_select($key, $field); break; case 'checkbox': case 'checkbox-multiple': case 'radio': $string .= self::display_field_checkbox($key, $field); break; case 'date': $string .= self::display_field_date($key, $field); $date_fields[] = $key; break; case 'time': $string .= self::display_field_time($key, $field); break; case 'attachment': $string .= self::display_field_attachment($key, $field); break; } // end switch if ('fieldset' != $field['type'] && 'fieldset-close' != $field['type'] && 'hidden' != $field['type']) { if ($field['notes_after'] != '') { $string .= self::ctf_notes($field['notes_after']) . "\n"; } } if ($open_div) { $string .= " </div>\n"; // close field div } } // end foreach (go through fields) // action hook for form display after fields $string = apply_filters('si_contact_display_after_fields', $string, self::$style, self::$form_errors, self::$form_id_num); // Are there any date fields? if (count($date_fields) > 0) { self::setup_calendar($date_fields); } // ********** Display stuff at the bottom of form ********** // close final outer container for field and follow groups if ($open_div) { $string .= '</div> <div ' . self::get_this_css('clear_style') . '></div>' . "\n"; } if (self::is_captcha_enabled(self::$form_id_num)) { $string .= self::display_captcha() . "\n"; } // hidden empty honeypot field, if enabled if (self::$form_options['honeypot_enable'] == 'true') { $honeypot_slug = self::get_todays_honeypot_slug($fields_in_use); $string .= ' ' . self::echo_if_error($honeypot_slug) . ' <div style="display:none;"> <label for="' . $honeypot_slug . self::$form_id_num . '"><small>' . __('Leave this field empty', 'si-contact-form') . '</small></label> <input type="text" name="' . $honeypot_slug . '" id="' . $honeypot_slug . self::$form_id_num . '" value="" /> </div> '; } // Display the submit button $string .= "\n<div " . 'id="fscf_submit_div' . self::$form_id_num . '" ' . self::get_this_css('submit_div_style') . '> <input type="submit" id="fscf_submit' . self::$form_id_num . '" ' . self::get_this_css('button_style') . ' value="'; $string .= self::$form_options['title_submit'] != '' ? esc_attr(self::$form_options['title_submit']) : esc_attr(__('Submit', 'si-contact-form')); $string .= '" '; if (!empty(self::$form_options['submit_attributes'])) { $string .= self::$form_options['submit_attributes'] . ' '; } if (self::$form_options['enable_areyousure'] == 'true') { $msg = self::$form_options['title_areyousure'] != '' ? esc_html(addslashes(self::$form_options['title_areyousure'])) : esc_html(addslashes(__('Are you sure?', 'si-contact-form'))); $string .= ' onclick="return confirm(\'' . $msg . '\')" '; } $string .= '/> '; if (self::$form_options['enable_reset'] == 'true') { $string .= '<input type="reset" id="fscf_reset' . self::$form_id_num . '" ' . self::get_this_css('reset_style') . ' value="'; $string .= self::$form_options['title_reset'] != '' ? esc_attr(self::$form_options['title_reset']) : esc_attr(__('Reset', 'si-contact-form')); $msg = addslashes(__('Do you really want to reset the form?', 'si-contact-form')); $string .= '" onclick="return confirm(\'' . $msg . '\')" />'; } $string .= "\n</div>\n"; if (self::$form_options['border_enable'] == 'true') { $string .= "</fieldset>\n"; } $string .= $hidden; // Close the form $string .= "\n</form>\n"; if (self::$form_options['enable_credit_link'] == 'true') { $string .= "\n <p " . self::convert_css(self::$form_options['powered_by_style']) . '>' . __('Powered by', 'si-contact-form') . ' <a href="http://wordpress.org/extend/plugins/si-contact-form/" target="_blank">' . __('Fast Secure Contact Form', 'si-contact-form') . "</a></p>\n"; } if (self::$form_options['vcita_scheduling_button'] == 'true' && self::is_vcita_activated()) { $string .= "</div>\n<div " . 'id="fscf_div_right_box' . self::$form_id_num . '" ' . self::get_this_css('right_box_style') . ">\n"; $string = self::display_vcita_scheduler_button($string); $string .= "\n</div>\n"; } $string .= '</div>'; // closes fscf-container $string .= "\r\n<div " . self::get_this_css('clear_style') . "></div>\n"; if (self::$placeholder && self::$form_options['external_style'] == 'false') { self::$add_placeholder_script = 1; // for adding the javascript $placeholder_style = self::$form_options['placeholder_style']; if (preg_match("/^style=\"(.*)\"\$/i", $placeholder_style, $matches)) { $placeholder_style = $matches[1]; } if (preg_match("/^class=\"(.*)\"\$/i", $placeholder_style, $matches)) { $placeholder_style = $matches[1]; } $string .= ' <style type="text/css"> /* Placeholder Style - WebKit browsers - Safari, Chrome */ ::-webkit-input-placeholder { ' . $placeholder_style . ' } /* Placeholder Style - Mozilla Firefox 4 - 18 */ :-moz-placeholder { ' . $placeholder_style . ' } /* Placeholder Style - Mozilla Firefox 19+ */ ::-moz-placeholder { ' . $placeholder_style . ' } /* Placeholder Style - Internet Explorer 10+ */ :-ms-input-placeholder { ' . $placeholder_style . ' } </style> '; } $string .= "\n" . '<!-- Fast Secure Contact Form plugin ' . FSCF_VERSION . ' - end - FastSecureContactForm.com -->' . "\n"; return $string; }