add hidden inputs in form

This commit is contained in:
2024-06-17 11:30:05 +03:00
parent d7584deff0
commit b4abd8eec6
6 changed files with 74 additions and 21 deletions

View File

@@ -301,6 +301,7 @@ document.write('<img src="'+pr+'?uid=18820&ref='+r+'&rd='+rd+'" width="88" heigh
</footer>
<?php get_template_part( 'partials/formhash' );?>
</body>
</html>

View File

@@ -989,6 +989,37 @@ function adddr_hash(){
}
//AMP
function add_amp_endpoint() {
add_rewrite_endpoint('amp', EP_PERMALINK);
}
add_action('init', 'add_amp_endpoint');
function custom_amp_template($template) {
if ( is_singular('post') && (isset($_GET['amp']) && $_GET['amp'] === '1')) {
$new_template = locate_template(array('single-amp.php'));
if (!empty($new_template)) {
return $new_template;
}
}
return $template;
}
add_filter('template_include', 'custom_amp_template');
function custom_amp_link() {
if (is_single()) {
$amp_url = get_permalink() . 'amp=1';
echo '<link rel="amphtml" href="' . esc_url($amp_url) . '">';
}
}
add_action('wp_head', 'custom_amp_link');
// Пример замены изображений на AMP-изображения в контенте поста
function convert_images_to_amp($content) {
if (function_exists('is_amp_endpoint') && is_amp_endpoint()) {

View File

@@ -8,7 +8,6 @@ get_header();
<div id="fulltext">
<? // режим подтверждение подписки
if (isset( $_GET['id'] )){
$sanitized_id = sanitize_text_field( $_GET['id'] );
@@ -22,12 +21,15 @@ if (isset( $_GET['id'] )){
}
elseif( !isset($_POST['mytext']) || $_POST['mytext'] !== ''){ // поле должно быть пустым - заполнить может только бот
echo '<p>Не можем подтвердить ваши данные. Пожалуйста, повторите попытку.</p>';
}
elseif ( !isset($_POST['subscription_nonce']) || !wp_verify_nonce($_POST['subscription_nonce'], 'subscription_form_nonce') ) {
echo ('<p>Неверный запрос. Пожалуйста, повторите попытку.</p>');
}
elseif( !isset($_POST['addrr']) || $_POST['addrr'] !== adddr_hash() ){
elseif( !isset($_POST['addrhash']) || $_POST['addrhash'] !== adddr_hash() ){
echo '<p>Не можем опеределить ваши данные. Пожалуйста, повторите попытку.</p>';
}

25
partials/formhash.php Executable file
View File

@@ -0,0 +1,25 @@
<?$addrhash = adddr_hash();
if ($addrhash !== null):?>
<script>
document.addEventListener('DOMContentLoaded', function() {
let form = document.getElementById('form-right');
let inputAdded = false;
form.addEventListener('mouseenter', function() {
if (!inputAdded) {
var hiddenInput = document.createElement("input");
hiddenInput.type = "hidden";
hiddenInput.name = "addrhash"; // имя поля
hiddenInput.value = "<?=$addrhash?>"; // значение поля
form.appendChild(hiddenInput);
inputAdded = true;
}
}, { once: true });
});
</script>
<?endif;?>

View File

@@ -2,14 +2,10 @@
<div id="convert"></div>
<div class="right_title"><?=vij_lang('email_title', LANG_VERSION);?></div>
<div id="subscript-mail">
<form class="form-right" action="https://vetandlife.ru/subscript" method="post">
<form class="form-right" id="form-right" action="https://vetandlife.ru/subscript" method="post">
<input сlass="frm_mail" type="email" required name="email" placeholder="<?=vij_lang('your_mail', LANG_VERSION);?>">
<?php wp_nonce_field('subscription_form_nonce', 'subscription_nonce'); ?>
<?$addr = adddr_hash();
if ($addr !== null):?>
<input type="hidden" name="addrr" value="<?=$addr?>">
<?endif?>
<input type="hidden" name="sender" value="info@vetandlife.ru">
<input type="text" class="mytext" name="mytext" placeholder="Дополнительный текст">
<button class="frm_submit"><?=vij_lang('email_btn', LANG_VERSION);?></button>
</form>
</div>

View File

@@ -1,12 +1,3 @@
<?php
// Включение стилей AMP
function theme_amp_styles() {
wp_enqueue_style('theme-amp-style', get_template_directory_uri() . '/amp.css');
}
add_action('amp_post_template_css', 'theme_amp_styles');
// Начало AMP страницы
?>
<!doctype html>
<html amp>
<head>
@@ -16,10 +7,17 @@ add_action('amp_post_template_css', 'theme_amp_styles');
<link rel="canonical" href="<?php echo esc_url(get_permalink()); ?>">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<style amp-custom>
<?php
// Включение стилей из amp.css
readfile(get_template_directory() . '/amp.css');
?>
body {
font-family: Arial, sans-serif;
padding: 20px;
}
h1 {
color: #333;
}
img {
max-width: 100%;
height: auto;
}
</style>
</head>
<body>