Jump to content
  • 0

Перевод полей формы


troll31
 Share

Question

Привет!

Я новичок в PHP, в компании стоит задача перевести контактную форму на русский язык. Перевожу ::$INPUT_LABEL_ATTR. - ничего не происходит. Подскажите, пожалуйста, где нужно в форме заменить английский текст на русский.

Код контактной связи


<?php

class Inc_Form_Shortcode extends Abstract_Inc_Shortcode implements Inc_Shortcode_Designer
{
static $ID_ATTR = "id";
static $ACTION_ATTR = "action";
static $CAPTCHA_ATTR = "captcha";
static $SUCCESS_MSG_ATTR = "success";
static $ERROR_MSG_ATTR = "error";
static $SUBMIT_LABEL_ATTR = "submit_label";
static $DISPLAY_LEGEND_ATTR = "display_legend";
static $INPUT_ID_ATTR = 'id';
static $INPUT_NAME_ATTR = 'name';
static $INPUT_TYPE_ATTR = 'type';
static $INPUT_REQUIRED_ATTR = 'required';
static $INPUT_LABEL_ATTR = 'label';
static $INPUT_VALUE_ATTR = 'value';
function render($attr, $inner_content = null, $code = "")
{
$content = '';
switch ($code) {
case "form":
$inner_content = do_shortcode($this->prepare_content($inner_content));
$content .= $this->render_form($attr, $inner_content);
break;
case "input":
$inner_content = do_shortcode($this->prepare_content($inner_content));
$content .= $this->render_form_input($attr, $inner_content);
break;
}
return $content;
}
private function render_form($attr, $inner_content)
{
extract(shortcode_atts(array(
Inc_Form_Shortcode::$ID_ATTR => '',
Inc_Form_Shortcode::$ACTION_ATTR => '#',
Inc_Form_Shortcode::$CAPTCHA_ATTR => 'false',
Inc_Form_Shortcode::$SUBMIT_LABEL_ATTR => '',
Inc_Form_Shortcode::$DISPLAY_LEGEND_ATTR => 'true',
Inc_Form_Shortcode::$SUCCESS_MSG_ATTR => '',
Inc_Form_Shortcode::$ERROR_MSG_ATTR => ''), $attr));
$submitButtonId = uniqid();
$successBoxId = uniqid();
$errorBoxId = uniqid();
$submit_label = !empty($submit_label) ? $submit_label : __('Submit', INCEPTIO_THEME_NAME);
$success = !empty($success) ? $success : __('The form has been successfully submitted', INCEPTIO_THEME_NAME);
$error = !empty($error) ? $error : __('The form couldn\'t be submitted because a server error occurred. Please try again later.', INCEPTIO_THEME_NAME);
$id = !empty($id) ? ' id="' . $id . '"' : '';
$form_action = site_url('wp-admin/admin-ajax.php');
$content = do_shortcode('[notif id="' . $successBoxId . '" type="success" display="false"]' . $success . '[/notif]');
$content .= do_shortcode('[notif id="' . $errorBoxId . '" type="error" display="false"]' . $error . '[/notif]');
$content .= "<form" . $id . " class=\"content-form\" method=\"post\" action=\"$form_action\">";
$content .= $inner_content;
if (inc_is_captcha_form_enabled() && $captcha == 'true') {
$content .= "<p>";
$content .= do_shortcode('[captcha][/captcha]');
$content .= "</p>";
}
$content .= "<p>";
$content .= "<input id=\"$submitButtonId\" class=\"button\" type=\"submit\" name=\"submit\" value=\"$submit_label\">";
$content .= "</p>";
$content .= "</form>";
if ($display_legend == 'true') {
$content .= "<p><span class=\"asterisk note\">*</span> " . __('Required fields', INCEPTIO_THEME_NAME) . "</p>";
}
$content .= "<script type=\"text/javascript\">
if(!document['formsSettings']){
document['formsSettings'] = [];
}
document['formsSettings'].push({
action: '" . $action . "',
submitButtonId: '" . $submitButtonId . "',
successBoxId: '" . $successBoxId . "',
errorBoxId: '" . $errorBoxId . "'
});
</script>";
return $content;
}
private function render_form_input($attr, $inner_content = null)
{
$content = '';
extract(shortcode_atts(array(
Inc_Form_Shortcode::$INPUT_ID_ATTR => uniqid(),
Inc_Form_Shortcode::$INPUT_NAME_ATTR => '',
Inc_Form_Shortcode::$INPUT_TYPE_ATTR => 'text',
Inc_Form_Shortcode::$INPUT_REQUIRED_ATTR => 'false',
Inc_Form_Shortcode::$INPUT_LABEL_ATTR => '',
Inc_Form_Shortcode::$INPUT_VALUE_ATTR => ''
), $attr));
$required_span = '';
$required_class = '';
if ($required == 'true') {
$required_span = "<span class=\"asterisk note\">*</span>";
$required_class = "class=\"required\"";
}
if ($type != 'submit') {
$content .= "<p>";
if ($type == 'hidden') {
$content .= "<input id=\"$id\" type=\"$type\" name=\"$name\" value=\"$value\">";
} elseif ($type == 'custom') {
$content .= "<label for=\"$id\">" . $label . ":$required_span</label>";
$content .= $inner_content;
} else {
if ($type == 'textarea') {
$content .= "<label for=\"$id\">" . $label . ":$required_span</label>";
$content .= "<textarea id=\"$id\" cols=\"68\" rows=\"8\" name=\"$name\" $required_class>$value</textarea>";
} elseif ($type == 'checkbox') {
$checked = ($value == 'on' || $value == 'checked') ? 'checked' : '';
$content .= "<input id=\"$id\" name=\"$name\" type=\"checkbox\" $required_class $checked>";
$content .= " <label for=\"$id\">" . $label . ":$required_span</label>";
} else {
$content .= "<label for=\"$id\">" . $label . ":$required_span</label>";
$content .= "<input id=\"$id\" type=\"$type\" name=\"$name\" value=\"$value\" $required_class>";
}
}
$content .= "</p>";
}
return $content;
}
function get_names()
{
return array('form', 'input');
}
function get_visual_editor_form()
{
$example1 = '[input '.Inc_Form_Shortcode::$ID_ATTR.'="name-id" '.Inc_Form_Shortcode::$INPUT_LABEL_ATTR.'="Имя" ' . Inc_Form_Shortcode::$INPUT_TYPE_ATTR . '="text" ' . Inc_Form_Shortcode::$INPUT_NAME_ATTR . '="name" ' . Inc_Form_Shortcode::$INPUT_REQUIRED_ATTR . '="true"][/input]';
$example1 .= '[input '.Inc_Form_Shortcode::$ID_ATTR.'="email-id" '.Inc_Form_Shortcode::$INPUT_LABEL_ATTR.'="Email" ' . Inc_Form_Shortcode::$INPUT_TYPE_ATTR . '="email" ' . Inc_Form_Shortcode::$INPUT_NAME_ATTR . '="email" ' . Inc_Form_Shortcode::$INPUT_REQUIRED_ATTR . '="true"][/input]';
$example1 .= '[input '.Inc_Form_Shortcode::$ID_ATTR.'="url-id" '.Inc_Form_Shortcode::$INPUT_LABEL_ATTR.'="Сайт" ' . Inc_Form_Shortcode::$INPUT_TYPE_ATTR . '="url" ' . Inc_Form_Shortcode::$INPUT_NAME_ATTR . '="url" ' . Inc_Form_Shortcode::$INPUT_REQUIRED_ATTR . '="false"][/input]';
$example1 .= '[input '.Inc_Form_Shortcode::$ID_ATTR.'="subject-id" '.Inc_Form_Shortcode::$INPUT_LABEL_ATTR.'="Тема" ' . Inc_Form_Shortcode::$INPUT_TYPE_ATTR . '="text" ' . Inc_Form_Shortcode::$INPUT_NAME_ATTR . '="subject" ' . Inc_Form_Shortcode::$INPUT_REQUIRED_ATTR . '="true"][/input]';
$example1 .= '[input '.Inc_Form_Shortcode::$ID_ATTR.'="message-id" '.Inc_Form_Shortcode::$INPUT_LABEL_ATTR.'="Сообщение" ' . Inc_Form_Shortcode::$INPUT_TYPE_ATTR . '="textarea" ' . Inc_Form_Shortcode::$INPUT_NAME_ATTR . '="message" ' . Inc_Form_Shortcode::$INPUT_REQUIRED_ATTR . '="true"][/input]';
$example1 = htmlspecialchars($example1);
$example1 = str_replace(array('[', ']'), array('[', ']'), $example1);
$example2 = '[input '.Inc_Form_Shortcode::$ID_ATTR.'="tf-id" '.Inc_Form_Shortcode::$INPUT_LABEL_ATTR.'="Имя" ' . Inc_Form_Shortcode::$INPUT_TYPE_ATTR . '="text" ' . Inc_Form_Shortcode::$INPUT_NAME_ATTR . '="name" ' . Inc_Form_Shortcode::$INPUT_REQUIRED_ATTR . '="true"][/input]';
$example2 .= '[input '.Inc_Form_Shortcode::$ID_ATTR.'="ef-id" '.Inc_Form_Shortcode::$INPUT_LABEL_ATTR.'="Email" ' . Inc_Form_Shortcode::$INPUT_TYPE_ATTR . '="email" ' . Inc_Form_Shortcode::$INPUT_NAME_ATTR . '="email" ' . Inc_Form_Shortcode::$INPUT_REQUIRED_ATTR . '="true"][/input]';
$example2 .= '[input '.Inc_Form_Shortcode::$ID_ATTR.'="erlf-id" '.Inc_Form_Shortcode::$INPUT_LABEL_ATTR.'="Сайт" ' . Inc_Form_Shortcode::$INPUT_TYPE_ATTR . '="url" ' . Inc_Form_Shortcode::$INPUT_NAME_ATTR . '="url" ' . Inc_Form_Shortcode::$INPUT_REQUIRED_ATTR . '="false"][/input]';
$example2 .= '[input '.Inc_Form_Shortcode::$ID_ATTR.'="cf-id" '.Inc_Form_Shortcode::$INPUT_LABEL_ATTR.'="Checkbox Field" ' . Inc_Form_Shortcode::$INPUT_TYPE_ATTR . '="checkbox" ' . Inc_Form_Shortcode::$INPUT_NAME_ATTR . '="checkbox" ' . Inc_Form_Shortcode::$INPUT_REQUIRED_ATTR . '="true"][/input]';
$example2 .= '[input '.Inc_Form_Shortcode::$ID_ATTR.'="custf-id" '.Inc_Form_Shortcode::$INPUT_LABEL_ATTR.'="Custom Field" ' . Inc_Form_Shortcode::$INPUT_TYPE_ATTR . '="custom" ' . Inc_Form_Shortcode::$INPUT_REQUIRED_ATTR . '="true"]<select id="custf-id" name="custom"><option value="op1">Option 1</option><option value="op2">Option 2</option></select>[/input]';
$example2 .= '[input '.Inc_Form_Shortcode::$ID_ATTR.'="taf-id" '.Inc_Form_Shortcode::$INPUT_LABEL_ATTR.'="Textarea Field" ' . Inc_Form_Shortcode::$INPUT_TYPE_ATTR . '="textarea" ' . Inc_Form_Shortcode::$INPUT_NAME_ATTR . '="textarea" ' . Inc_Form_Shortcode::$INPUT_REQUIRED_ATTR . '="true"][/input]';
$example2 = htmlspecialchars($example2);
$example2 = str_replace(array('[', ']'), array('[', ']'), $example2);
$content = '<form id="sc-form-form" class="generic-form" method="post" action="#" data-sc="form">';
$content .= '<fieldset>';
$content .= '<div>';
$content .= '<label for="sc-form-ext">' . __('Example Type', INCEPTIO_THEME_NAME) . ':</label>';
$content .= '<select id="sc-form-ext" name="sc-form-ext">';
$content .= '<option value="contact">' . __('Contact Form Example', INCEPTIO_THEME_NAME) . '</option>';
$content .= '<option value="basic">' . __('Basic Form Example', INCEPTIO_THEME_NAME) . '</option>';
$content .= '</select>';
$content .= '</div>';
$content .= '<div>';
$content .= '<label for="sc-form-id">' . __('ID', INCEPTIO_THEME_NAME) . ':</label>';
$content .= '<input id="sc-form-id" name="sc-form-action" type="text" data-attr-name="' . Inc_Form_Shortcode::$ID_ATTR . '" data-attr-type="attr">';
$content .= '</div>';
$content .= '<div>';
$content .= '<label for="sc-form-action">' . __('Action', INCEPTIO_THEME_NAME) . ':</label>';
$content .= '<input id="sc-form-action" name="sc-form-action" type="text" data-attr-name="' . Inc_Form_Shortcode::$ACTION_ATTR . '" data-attr-type="attr" class="required">';
$content .= '</div>';
$content .= '<div>';
$content .= '<input id="sc-form-captcha" name="sc-form-captcha" type="checkbox" data-attr-name="' . Inc_Form_Shortcode::$CAPTCHA_ATTR . '" data-attr-type="attr">';
$content .= '<label for="sc-form-captcha">' . __('Add Captcha', INCEPTIO_THEME_NAME) . '</label>';
$content .= '</div>';
$content .= '<div>';
$content .= '<label for="sc-form-sl">' . __('Submit Label', INCEPTIO_THEME_NAME) . ':</label>';
$content .= '<input id="sc-form-sl" name="sc-form-sl" type="text" data-attr-name="' . Inc_Form_Shortcode::$SUBMIT_LABEL_ATTR . '" data-attr-type="attr">';
$content .= '</div>';
$content .= '<div>';
$content .= '<label for="sc-form-success">' . __('Success Message', INCEPTIO_THEME_NAME) . ':</label>';
$content .= '<input id="sc-form-success" name="sc-form-success" type="text" data-attr-name="' . Inc_Form_Shortcode::$SUCCESS_MSG_ATTR . '" data-attr-type="attr">';
$content .= '</div>';
$content .= '<div>';
$content .= '<label for="sc-form-error">' . __('Error Message', INCEPTIO_THEME_NAME) . ':</label>';
$content .= '<input id="sc-form-error" name="sc-form-error" type="text" data-attr-name="' . Inc_Form_Shortcode::$ERROR_MSG_ATTR . '" data-attr-type="attr">';
$content .= '</div>';
$content .= '<div>';
$content .= '<input id="sc-form-dl" name="sc-form-dl" type="checkbox" checked data-attr-name="' . Inc_Form_Shortcode::$DISPLAY_LEGEND_ATTR . '" data-attr-type="attr">';
$content .= '<label for="sc-form-dl">' . __('Display Legend', INCEPTIO_THEME_NAME) . '</label>';
$content .= '</div>';
$content .= '<div >';
$content .= '<input id="sc-form-ex-contact" type="hidden" value="' . $example1 . '">';
$content .= '<input id="sc-form-ex-basic" type="hidden" value="' . $example2 . '">';
$content .= '<input id="sc-form-form-submit" type="submit" name="submit" value="' . __('Insert Form', INCEPTIO_THEME_NAME) . '" class="button-primary">';
$content .= '</div>';
$content .= '</fieldset>';
$content .= '</form>';
return $content;
}
function get_group_title()
{
return __('Others', INCEPTIO_THEME_NAME);
}
function get_title()
{
return __('Form', INCEPTIO_THEME_NAME);
}
}

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy