-
-
Save AntoscencoVladimir/3e8fc454fa335c720d60cfe6b46be789 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class dekaForm{ | |
function getData(){ | |
$data = ""; | |
$data[] .= fw_get_db_settings_option('email_form'); | |
$data[] .= fw_get_db_settings_option('subject'); | |
return $data; | |
} | |
function renderDekaForm(){ | |
$form = ""; | |
$form .= "<form id=\"consForm\" name=\"consForm\" method=\"post\">"; | |
$form .= "<input id=\"email\" name=\"email\" type=\"email\" placeholder=\"Ваш e-mail\">"; | |
$form .= "<div id=\"subBlock\">"; | |
$form .= "<input id=\"submitBtn\" name=\"submitBtn\" type=\"submit\" value=\"Отправить\"><i class=\"fa fa-long-arrow-right\" aria-hidden=\"true\"></i>"; | |
$form .= "</div>"; | |
$form .= "</form>"; | |
$form .= "<div id=\"status-area\">"; | |
$form .= "</div>"; | |
echo $form; | |
} | |
function getValuesAndSubmit($input_value){ | |
$email = "Новая заявка на консультацию: " . $input_value ; | |
$to = $this->getData()[0]; | |
$subject = $this->getData()[1]; | |
$headers = array(); | |
$headers[] = "MIME-Version: 1.0"; | |
$headers[] = "Content-type: text/plain; charset=UTF-8"; | |
$headers[] = "From: <dekaroom>"; | |
$headers[] = "Bcc: <{$input_value}>"; | |
$headers[] = "Reply-To: <{$input_value}>"; | |
$headers[] = "Subject: {$subject}"; | |
$headers[] = "X-Mailer: PHP/".phpversion(); | |
mail($to, $subject, $email, implode("\r\n", $headers)); | |
} | |
} | |
Вывод формы | |
<?php | |
$deka_form = new dekaForm(); | |
$deka_form->renderDekaForm(); | |
if(isset($_POST['email'])) | |
{ | |
$input_value = $_POST['email']; | |
$deka_form->getValuesAndSubmit($input_value); | |
} | |
?> | |
AJAX | |
<script> | |
jQuery(document).ready(function() { | |
jQuery("#consForm").submit(function() { | |
jQuery.ajax({ | |
type: "POST", | |
data: jQuery(this).serialize() | |
}).done(function() { | |
jQuery(this).find("input").val(""); | |
jQuery('#status-area').flash_message({ | |
text: 'Спасибо, отправлено!', | |
how: 'append' | |
}).css({ | |
'text-transform':'uppercase', | |
'font-size':'12px', | |
'padding-top':'20px' | |
}); | |
jQuery("#consForm").trigger("reset"); | |
}); | |
return false; | |
}); | |
(function($) { | |
jQuery.fn.flash_message = function(options) { | |
options = $.extend({ | |
text: 'Done', | |
time: 1100, | |
how: 'before', | |
class_name: '' | |
}, options); | |
return jQuery(this).each(function() { | |
if( jQuery(this).parent().find('.flash_message').get(0) ) | |
return; | |
var message = jQuery('<span />', { | |
'class': 'flash_message ' + options.class_name, | |
text: options.text | |
}).hide().fadeIn('fast'); | |
jQuery(this)[options.how](message); | |
message.delay(options.time).fadeOut('normal', function() { | |
jQuery(this).remove(); | |
}); | |
}); | |
}; | |
})(jQuery); | |
}); | |
</script> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment