/** * The same above, but this print the string and not return. * * @since 1.0 */ function yiw_convertTags($str, $class = '', $after = '') { echo yiw_get_convertTags($str, $class, $after); }
function yiw_module($form, $echo = true) { $fields = unserialize(yiw_get_option('contact_fields_' . $form)); if (!is_array($fields) or empty($fields)) { return null; } global $message; //echo '<pre>', print_r($fields), '</pre>'; $html = '<form id="contact-form-' . $form . '" class="contact-form" method="post" action="" enctype="multipart/form-data">' . "\n\n"; // div message feedback $html .= "\t<div class=\"usermessagea\">" . yiw_module_general_message_of($form, false) . "</div>\n"; $html .= "\t<fieldset>\n\n"; $html .= "\t\t<ul>\n\n"; // array with all messages for js validate $js_messages = array(); foreach ($fields as $id => $field) { // classes $input_class = array(); // array for print input's classes $li_class = array($field['type'] . '-field'); // array for print li's classes // errors $error_msg = ''; $error = false; $js_messages[$field['data_name']] = $field['msg_error']; if (isset($message[$form][$field['data_name']])) { $error = TRUE; $error_msg = $message[$form][$field['data_name']]; } // li class if ($field['class'] != '') { $li_class[] = " {$field['class']}"; } if ($error) { array_push($input_class, 'icon', 'error'); } $html .= "\t\t\t<li class=\"" . implode($li_class, ' ') . "\">\n"; $html .= "\t\t\t\t<label for=\"{$field['data_name']}-{$form}\">\n"; $html .= yiw_string_("\t\t\t\t\t" . '<span class="label">', yiw_get_convertTags(stripslashes_deep($field['title']), 'highlight-text'), '</span>' . "\n", false); $html .= yiw_string_("<br />\t\t\t\t\t" . '<span class="sublabel">', stripslashes_deep($field['description']), '</span><br />' . "\n", false); $html .= "\t\t\t\t</label>\n"; // if required if (isset($field['required']) and $field['required'] == 'yes') { $input_class[] = 'required'; } if (isset($field['email_validate']) and $field['email_validate'] == 'yes') { $input_class[] = 'email-validate'; } // retrive value if (isset($field['data_name']) && !$error) { $value = yiw_get_value($field['data_name']); } else { if (isset($_GET[$field['data_name']])) { $value = $_GET[$field['data_name']]; } else { $value = ''; } } // only for clean code $html .= "\t\t\t\t"; // print type of input switch ($field['type']) { // text case 'text': $html .= "<input type=\"text\" name=\"yiw_contact[" . $field['data_name'] . "]\" id=\"" . $field['data_name'] . "-{$form}\" class=\"" . implode($input_class, ' ') . "\" value=\"{$value}\" />"; break; // checkbox // checkbox case 'checkbox': $checked = ''; if ($value != '' and $value) { $checked = ' checked="checked"'; } else { if ($field['already_checked'] == 'yes') { $checked = ' checked="checked"'; } } $html .= "<input type=\"checkbox\" name=\"yiw_contact[" . $field['data_name'] . "]\" id=\"" . $field['data_name'] . "-{$form}\" value=\"1\" class=\"" . implode($input_class, ' ') . "\"{$checked} />"; $html .= ' ' . $field['label_checkbox']; break; // select // select case 'select': $html .= "<select name=\"yiw_contact[" . $field['data_name'] . "]\" id=\"" . $field['data_name'] . "-{$form}\">\n"; // options foreach ($field['option'] as $id => $option) { $selected = ''; if ($field['option_selected'] == $id) { $selected = ' selected="selected"'; } $html .= "\t\t\t\t\t\t<option value=\"{$option}\"{$selected}>{$option}</option>\n"; } $html .= "\t\t\t\t\t</select>"; break; // textarea // textarea case 'textarea': $html .= "<textarea name=\"yiw_contact[" . $field['data_name'] . "]\" id=\"" . $field['data_name'] . "-{$form}\" rows=\"8\" cols=\"30\" class=\"" . implode($input_class, ' ') . "\">{$value}</textarea>"; break; // radio // radio case 'radio': // options foreach ($field['option'] as $i => $option) { $selected = ''; if ($field['option_selected'] == $i) { $selected = ' checked=""'; } $html .= "\t\t\t\t\t\t<input type=\"radio\" name=\"yiw_contact[{$field[data_name]}]\" id=\"{$field[data_name]}-{$form}-{$i}\" value=\"{$option}\"{$selected} /> {$option}<br />\n"; } break; // password // password case 'password': $html .= "<input type=\"password\" name=\"yiw_contact[{$field[data_name]}]\" id=\"{$field[data_name]}-{$form}\" class=\"" . implode($input_class, ' ') . "\" value=\"{$value}\" />"; break; // file // file case 'file': $html .= "<input type=\"file\" name=\"yiw_contact[{$field[data_name]}]\" id=\"{$field[data_name]}-{$form}\" class=\"" . implode($input_class, ' ') . "\" />"; break; } // only for clean code $html .= "\n"; $html .= "\t\t\t\t<div class=\"msg-error\">" . $error_msg . "</div>\n"; $html .= "\t\t\t</li>\n"; } $html .= "\t\t\t<li class=\"submit-button\">\n"; $html .= "\t\t\t\t<input type=\"text\" name=\"email_check_2\" id=\"email_check_2\" style=\"position:absolute; left:-99999px\" value=\"\" />\n"; $html .= "\t\t\t\t<input type=\"hidden\" name=\"yiw_action\" value=\"sendemail\" id=\"yiw_action\" />\n"; $html .= "\t\t\t\t<input type=\"hidden\" name=\"yiw_referer\" value=\"" . yiw_curPageURL() . "\" />\n"; $html .= "\t\t\t\t<input type=\"hidden\" name=\"id_form\" value=\"" . str_replace('-', '_', $form) . "\" />\n"; $html .= "\t\t\t\t<input type=\"submit\" name=\"yiw_sendemail\" value=\"" . yiw_get_option('contact_form_submit_label_' . $form, __('send message', 'yiw')) . "\" class=\"sendmail " . yiw_get_option('contact_form_submit_alignment_' . $form, __('alignright', 'yiw')) . "\" />"; $html .= "\t\t\t</li>\n"; $html .= "\t\t</ul>\n\n"; $html .= "\t</fieldset>\n"; $html .= "</form>\n\n"; // messages for javascript validation $html .= "<script type=\"text/javascript\">\n"; $html .= "\tvar messages_form_" . str_replace('-', '_', $form) . " = {\n"; foreach ($js_messages as $id => $msg) { $html .= "\t\t{$id}: \"{$msg}\",\n"; } // remove last comma $html = str_replace("\t\t{$id}: \"{$msg}\",\n", "\t\t{$id}: \"{$msg}\"\n", $html); $html .= "\t};\n"; $html .= "</script>"; if ($echo) { echo $html; } return $html; }