function getFormCode($form, $is_widget_form = false) { ccf_utils::startSession(); if (empty($form)) { return ''; } $admin_options = parent::getAdminOptions(); $form_key = time(); $out = ''; $form_styles = ''; $style_class = !$is_widget_form ? ' customcontactform' : ' customcontactform-sidebar'; $form_id = esc_attr('form-' . $form->id . '-' . $form_key); if ($form->form_style != 0) { $style = parent::selectStyle($form->form_style, ''); $style_class = $style->style_slug; } $form_method = empty($form->form_method) ? 'post' : strtolower($form->form_method); $form_title = ccf_utils::decodeOption($form->form_title, 1, 1); $action = !empty($form->form_action) ? $form->form_action : $_SERVER['REQUEST_URI']; $file_upload_form = ''; //$out .= '<form id="'.$form_id.'" method="'.$form_method.'" action="'.$action.'" class="'.$style_class.'">' . "\n"; $out .= ccf_utils::decodeOption($form->custom_code, 1, 1) . "\n"; if (!empty($form_title) && !$is_widget_form) { $out .= '<h4 id="h4-' . esc_attr($form->id) . '-' . $form_key . '">' . esc_html($form_title) . '</h4>' . "\n"; } $fields = parent::getAttachedFieldsArray($form->id); $hiddens = ''; $code_type = $admin_options['code_type'] == 'XHTML' ? ' /' : ''; $add_reset = ''; foreach ($fields as $field_id) { $field = parent::selectField($field_id, ''); $req = ($field->field_required == 1 or $field->field_slug == 'ishuman') ? '* ' : ''; $req_long = $field->field_required == 1 ? ' ' . __('(required)', 'custom-contact-forms') : ''; $input_id = 'id="' . ccf_utils::decodeOption($field->field_slug, 1, 1) . '-' . $form_key . '"'; $field_value = esc_attr(ccf_utils::decodeOption($field->field_value, 1, 1)); $instructions = empty($field->field_instructions) ? '' : 'title="' . esc_attr($field->field_instructions) . $req_long . '" '; $tooltip_class = empty($field->field_instructions) ? '' : 'ccf-tooltip-field'; if ($admin_options['enable_widget_tooltips'] == 0 && $is_widget_form) { $instructions = ''; } if (isset($_SESSION['ccf_fields'][$field->field_slug])) { if ($admin_options['remember_field_values'] == 1) { $field_value = esc_attr($_SESSION['ccf_fields'][$field->field_slug]); } } if ($field->field_slug == 'captcha') { $out .= '<div>' . "\n" . $this->getCaptchaCode($field, $form->id) . "\n" . '</div>' . "\n"; } elseif ($field->field_slug == 'recaptcha') { $out .= '<div>' . "\n" . $this->getReCaptchaCode($field, $form->id) . "\n" . '</div>' . "\n"; } elseif ($field->field_slug == 'usaStates') { $field->field_value = $field_value; $out .= '<div>' . "\n" . $this->getStatesCode($field, $form->id) . "\n" . '</div>' . "\n"; } elseif ($field->field_slug == 'ishuman') { $field->field_value = $field_value; $out .= '<div>' . "\n" . $this->getIsHumanCode($field, $form->id) . "\n" . '</div>' . "\n"; } elseif ($field->field_slug == 'allCountries') { $field->field_value = $field_value; $out .= '<div>' . "\n" . $this->getCountriesCode($field, $form->id) . "\n" . '</div>' . "\n"; } elseif ($field->field_slug == 'resetButton') { $add_reset = ' <input type="reset" ' . $instructions . ' class="reset-button ' . $field->field_class . ' ' . $tooltip_class . '" value="' . esc_attr($field->field_value) . '" />'; } elseif ($field->field_type == 'Text') { $maxlength = (empty($field->field_maxlength) or $field->field_maxlength <= 0) ? '' : ' maxlength="' . esc_attr($field->field_maxlength) . '"'; $out .= '<div>' . "\n" . '<label for="' . ccf_utils::decodeOption($field->field_slug, 1, 1) . '">' . $req . ccf_utils::decodeOption($field->field_label, 1, 1) . '</label>' . "\n" . '<input class="' . esc_attr($field->field_class) . ' ' . $tooltip_class . '" ' . $instructions . ' ' . $input_id . ' type="text" name="' . ccf_utils::decodeOption($field->field_slug, 1, 1) . '" value="' . $field_value . '"' . $maxlength . '' . $code_type . '>' . "\n" . '</div>' . "\n"; } elseif ($field->field_type == 'File') { $file_upload_form = ' enctype="multipart/form-data" '; $out .= '<div>' . "\n" . '<label for="' . ccf_utils::decodeOption($field->field_slug, 1, 1) . '">' . $req . ccf_utils::decodeOption($field->field_label, 1, 1) . '</label>' . "\n" . '<input class="' . esc_attr($field->field_class) . ' ' . $tooltip_class . '" ' . $instructions . ' ' . $input_id . ' type="file" name="' . ccf_utils::decodeOption($field->field_slug, 1, 1) . '" value="' . $field_value . '"' . $code_type . '>' . "\n" . '</div>' . "\n"; } elseif ($field->field_type == 'Date') { $maxlength = (empty($field->field_maxlength) or $field->field_maxlength <= 0) ? '' : ' maxlength="' . $field->field_maxlength . '"'; $out .= '<div>' . "\n" . '<label for="' . ccf_utils::decodeOption($field->field_slug, 1, 1) . '">' . $req . ccf_utils::decodeOption($field->field_label, 1, 1) . '</label>' . "\n" . '<input class="' . esc_attr($field->field_class) . ' ccf-datepicker ' . $tooltip_class . '" ' . $instructions . ' ' . $input_id . ' type="text" name="' . ccf_utils::decodeOption($field->field_slug, 1, 1) . '" value="' . $field_value . '"' . $maxlength . '' . $code_type . '>' . "\n" . '</div>' . "\n"; } elseif ($field->field_type == 'Hidden') { $hiddens .= '<input type="hidden" name="' . ccf_utils::decodeOption($field->field_slug, 1, 1) . '" value="' . $field_value . '" ' . $input_id . '' . $code_type . '>' . "\n"; } elseif ($field->field_type == 'Textarea') { $out .= '<div>' . "\n" . '<label for="' . ccf_utils::decodeOption($field->field_slug, 1, 1) . '">' . $req . ccf_utils::decodeOption($field->field_label, 1, 1) . '</label>' . "\n" . '<textarea class="' . esc_attr($field->field_class) . ' ' . $tooltip_class . '" ' . $instructions . ' ' . $input_id . ' rows="5" cols="40" name="' . ccf_utils::decodeOption($field->field_slug, 1, 1) . '">' . $field_value . '</textarea>' . "\n" . '</div>' . "\n"; } elseif ($field->field_type == 'Dropdown') { $field_options = ''; $options = parent::getAttachedFieldOptionsArray($field->id); foreach ($options as $option_id) { $option = parent::selectFieldOption($option_id); $option_sel = ($field_value == $option->option_label || $field_value == $option->option_value) && !empty($field_value) ? ' selected="selected"' : ''; $option_value = !empty($option->option_value) ? ' value="' . esc_attr($option->option_value) . '"' : ''; // Weird way of marking a state dead. TODO: Find another way. $option_value = $option->option_dead == 1 ? ' value="' . CCF_DEAD_STATE_VALUE . '"' : $option_value; $field_options .= '<option' . $option_sel . '' . $option_value . '>' . esc_attr($option->option_label) . '</option>' . "\n"; } if (!empty($options)) { if (!$is_widget_form) { $out .= '<div>' . "\n" . '<label for="' . ccf_utils::decodeOption($field->field_slug, 1, 1) . '">' . $req . ccf_utils::decodeOption($field->field_label, 1, 1) . '</label>' . "\n" . '<select ' . $instructions . ' ' . $input_id . ' name="' . ccf_utils::decodeOption($field->field_slug, 1, 1) . '" class="' . esc_attr($field->field_class) . ' ' . $tooltip_class . '">' . "\n" . $field_options . '</select>' . "\n" . '</div>' . "\n"; } else { $out .= '<div>' . "\n" . '<label for="' . ccf_utils::decodeOption($field->field_slug, 1, 1) . '">' . $req . ccf_utils::decodeOption($field->field_label, 1, 1) . '</label>' . "\n" . '<select class="' . esc_attr($field->field_class) . ' ' . $tooltip_class . '" ' . $instructions . ' ' . $input_id . ' name="' . ccf_utils::decodeOption($field->field_slug, 1, 1) . '">' . "\n" . $field_options . '</select>' . "\n" . '</div>' . "\n"; } } } elseif ($field->field_type == 'Radio') { $field_options = ''; $options = parent::getAttachedFieldOptionsArray($field->id); foreach ($options as $option_id) { $option = parent::selectFieldOption($option_id); $option_sel = ($field_value == $option->option_label || $field_value == $option->option_value) && !empty($field_value) ? ' checked="checked"' : ''; $field_options .= '<div><input' . $option_sel . ' class="' . esc_attr($field->field_class) . ' ' . $tooltip_class . '" type="radio" ' . $instructions . ' name="' . ccf_utils::decodeOption($field->field_slug, 1, 1) . '" value="' . ccf_utils::decodeOption($option->option_value, 1, 1) . '"' . $code_type . '> <label class="select" for="' . ccf_utils::decodeOption($field->field_slug, 1, 1) . '">' . ccf_utils::decodeOption($option->option_label, 1, 1) . '</label></div>' . "\n"; } $field_label = !empty($field->field_label) ? '<label for="' . ccf_utils::decodeOption($field->field_slug, 1, 1) . '">' . $req . ccf_utils::decodeOption($field->field_label, 1, 1) . '</label>' : ''; if (!empty($options)) { $out .= '<div>' . "\n" . $field_label . "\n" . $field_options . "\n" . '</div>' . "\n"; } } elseif ($field->field_type == 'Checkbox') { $field_options = ''; $options = parent::getAttachedFieldOptionsArray($field->id); $z = 0; foreach ($options as $option_id) { $option = parent::selectFieldOption($option_id); $field_value_array = !is_array($field_value) ? array() : $field_value; $option_sel = in_array($option->option_label, $field_value_array) || in_array($option->option_value, $field_value_array) ? ' checked="checked"' : ''; $check_value = empty($option->option_value) ? esc_html($option->option_label) : ccf_utils::decodeOption($option->option_value, 1, 1); $field_options .= '<div><input' . $option_sel . ' class="' . esc_attr($field->field_class) . ' ' . $tooltip_class . '" type="checkbox" ' . $instructions . ' name="' . ccf_utils::decodeOption($field->field_slug, 1, 1) . '[' . $z . ']" value="' . $check_value . '"' . $code_type . '> <label class="select" for="' . ccf_utils::decodeOption($field->field_slug, 1, 1) . '">' . ccf_utils::decodeOption($option->option_label, 1, 1) . '</label></div>' . "\n"; $z++; } $field_label = !empty($field->field_label) ? '<label for="' . ccf_utils::decodeOption($field->field_slug, 1, 1) . '">' . $req . ccf_utils::decodeOption($field->field_label, 1, 1) . '</label>' : ''; if (!empty($options)) { $out .= '<div>' . "\n" . $field_label . "\n" . $field_options . "\n" . '</div>' . "\n"; } } } if (!empty($file_upload_form)) { $out = '<input type="hidden" name="MAX_FILE_SIZE" value="' . intval($admin_options['max_file_upload_size']) * 1000 * 1000 . '" />' . "\n" . $out; } $out = '<form id="' . $form_id . '" method="' . esc_attr($form_method) . '" action="' . esc_url($action) . '" class="' . esc_attr($style_class) . '"' . $file_upload_form . '>' . "\n" . $out; $submit_text = !empty($form->submit_button_text) ? ccf_utils::decodeOption($form->submit_button_text, 1, 0) : __('Submit', 'custom-contact-forms'); $out .= '<input name="form_page" value="' . esc_url($_SERVER['REQUEST_URI']) . '" type="hidden"' . $code_type . '>' . "\n" . '<input type="hidden" name="fid" value="' . esc_attr($form->id) . '"' . $code_type . '>' . "\n" . $hiddens . "\n" . '<input type="submit" id="submit-' . esc_attr($form->id) . '-' . $form_key . '" class="submit" value="' . $submit_text . '" name="customcontactforms_submit"' . $code_type . '>'; if (!empty($add_reset)) { $out .= $add_reset; } $out .= "\n" . '</form>'; if ($form->form_style != 0) { $no_border = array('', '0', '0px', '0%', '0pt', '0em'); $round_border = !in_array($style->field_borderround, $no_border) ? '-moz-border-radius:' . esc_attr($style->field_borderround) . '; -khtml-border-radius:' . esc_attr($style->field_borderround) . '; -webkit-border-radius:' . esc_attr($style->field_borderround) . '; ' : ''; $round_border_none = '-moz-border-radius:0px; -khtml-border-radius:0px; -webkit-border-radius:0px; '; $form_styles .= '<style type="text/css">' . "\n"; $form_styles .= '#' . $form_id . " { width: " . esc_attr($style->form_width) . "; text-align:left; padding:" . esc_attr($style->form_padding) . "; margin:" . esc_attr($style->form_margin) . "; border:" . esc_attr($style->form_borderwidth) . " " . esc_attr($style->form_borderstyle) . " #" . esc_attr(parent::formatStyle($style->form_bordercolor)) . "; background-color:#" . esc_attr(parent::formatStyle($style->form_backgroundcolor)) . "; font-family:" . esc_attr($style->form_fontfamily) . "; } \n"; $form_styles .= '#' . $form_id . " div { margin-bottom:6px; background-color:inherit; }\n"; $form_styles .= '#' . $form_id . " div div { margin:0; background-color:inherit; padding:0; }\n"; $form_styles .= '#' . $form_id . " h4 { padding:0; background-color:inherit; margin:" . esc_attr($style->title_margin) . " " . esc_attr($style->title_margin) . " " . esc_attr($style->title_margin) . " 0; color:#" . esc_attr(parent::formatStyle($style->title_fontcolor)) . "; font-size:" . esc_attr($style->title_fontsize) . "; } \n"; $form_styles .= '#' . $form_id . " label { padding:0; background-color:inherit; margin:" . esc_attr($style->label_margin) . " " . esc_attr($style->label_margin) . " " . esc_attr($style->label_margin) . " 0; display:block; color:#" . esc_attr(parent::formatStyle($style->label_fontcolor)) . "; width:" . esc_attr($style->label_width) . "; font-size:" . esc_attr($style->label_fontsize) . "; } \n"; $form_styles .= '#' . $form_id . " div div input { margin-bottom:2px; line-height:normal; }\n"; $form_styles .= '#' . $form_id . " input[type=checkbox] { margin:0; }\n"; $form_styles .= '#' . $form_id . " label.checkbox, #" . $form_id . " label.radio, #" . $form_id . " label.select { display:inline; } \n"; $form_styles .= '#' . $form_id . " input[type=text], #" . $form_id . " select { " . $round_border . " color:#" . esc_attr(parent::formatStyle($style->field_fontcolor)) . "; margin:0; width:" . esc_attr($style->input_width) . "; font-size:" . esc_attr($style->field_fontsize) . "; background-color:#" . esc_attr(parent::formatStyle($style->field_backgroundcolor)) . "; border:1px " . esc_attr($style->field_borderstyle) . " #" . esc_attr(parent::formatStyle($style->field_bordercolor)) . "; } \n"; $form_styles .= '#' . $form_id . " select { " . $round_border_none . " width:" . esc_attr($style->dropdown_width) . "; }\n"; $form_styles .= '#' . $form_id . " .submit { color:#" . esc_attr(parent::formatStyle($style->submit_fontcolor)) . "; width:" . esc_attr($style->submit_width) . "; height:" . esc_attr($style->submit_height) . "; font-size:" . esc_attr($style->submit_fontsize) . "; } \n"; if (!empty($style->submit_background)) { $form_styles .= '#' . $form_id . " .submit { background:url(" . esc_attr($style->submit_background) . ") " . esc_attr($style->submit_background_repeat) . " top left; border:0; }"; } $form_styles .= '#' . $form_id . " .reset-button { color:#" . esc_attr(parent::formatStyle($style->submit_fontcolor)) . "; width:" . esc_attr($style->submit_width) . "; height:" . esc_attr($style->submit_height) . "; font-size:" . esc_attr($style->submit_fontsize) . "; } \n"; $form_styles .= '#' . $form_id . " textarea { " . $round_border . " color:#" . esc_attr(parent::formatStyle($style->field_fontcolor)) . "; width:" . esc_attr($style->textarea_width) . "; margin:0; background-color:#" . esc_attr(parent::formatStyle($style->textarea_backgroundcolor)) . "; font-family:" . esc_attr($style->form_fontfamily) . "; height:" . esc_attr($style->textarea_height) . "; font-size:" . esc_attr($style->field_fontsize) . "; border:1px " . esc_attr($style->field_borderstyle) . " #" . esc_attr(parent::formatStyle($style->field_bordercolor)) . "; } \n"; $form_styles .= '.ccf-tooltip { background-color:#' . esc_attr(parent::formatStyle($style->tooltip_backgroundcolor)) . '; font-family:' . esc_attr($style->form_fontfamily) . '; font-color:#' . esc_attr(parent::formatStyle($style->tooltip_fontcolor)) . '; font-size:' . esc_attr($style->tooltip_fontsize) . '; }' . "\n"; $form_styles .= '</style>' . "\n"; } return $form_styles . $out; }