Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $('form input').tooltip({
- trigger: 'manual',
- placement: 'bottom',
- container: 'body'
- }).on('shown.bs.tooltip', function (e) {
- $(e.target).on('focus', function () {
- $(e.target).tooltip('hide');
- })
- /*setTimeout(function () {
- $(e.target).tooltip('hide');//.removeAttr('data-original-title');
- }, 5000)*/
- })
- $('form.form-ajax').submit(function (evt) {
- var eForm = $(this);
- preloader(eForm);
- eForm.find('[data-original-title]').removeAttr('data-original-title');
- $.post(eForm.attr('action'), eForm.serialize()).done(function (res) {
- preloader(eForm, false);
- var oRes = $.parseJSON(res);
- //console.info(oRes);
- eForm.find('.err').removeClass('err');
- if (oRes.is) {
- eForm[0].reset();
- showMessage(oRes.title, oRes.msg);
- } else {
- oRes.fields.forEach(function (sField, i) {
- var eField = eForm.find('[name='+ sField +']');
- eField.addClass('err').attr('data-original-title', oRes.msg[i]);
- eField.tooltip('show');
- })
- }
- });
- evt.preventDefault();
- })
- function preloader (eElem, is = true) {
- var eIconPreloader = $('<i/>');
- ePreloader = $('<div class="preloader js-preloader"/>').append(eIconPreloader);
- if (is) {
- eElem.children().addClass('loading');
- eElem.append(ePreloader);
- } else {
- eElem.children('.js-preloader').remove();
- eElem.children().removeClass('loading');
- }
- }
- /* PHP
- */
- <? if (isset($_POST['type'])) {
- $aRes = array(
- 'is' => true,
- 'type' => $_POST['type'],
- 'msg' => array(),
- 'data' => false
- );
- switch ($_POST['type']) {
- case 'individual-programm':
- $aRes['title'] = '';
- $aRes['fields'] = array();
- $name = clearField($_POST['name']);
- $phone = clearField($_POST['phone']);
- $company = clearField($_POST['company']);
- $email = clearField($_POST['email']);
- $isAccept = (isset($_POST['accept']));
- if (!$isAccept) {
- $aRes['is'] = false;
- $aRes['title'] = 'Ошибка!';
- array_push($aRes['msg'], 'Чтобы продолжить, нужно принять условия пользовательского соглашения');
- array_push($aRes['fields'], 'accept');
- }
- if (empty($phone)) {
- $aRes['is'] = false;
- $aRes['title'] = 'Ошибка!';
- array_push($aRes['msg'], 'Введите ваш телефон');
- array_push($aRes['fields'], 'phone');
- } elseif (!isPhone($phone)) {
- $aRes['is'] = false;
- $aRes['title'] = 'Ошибка!';
- array_push($aRes['msg'], 'Телефон заполнен не верно');
- array_push($aRes['fields'], 'phone');
- }
- if (empty($name)) {
- $aRes['is'] = false;
- $aRes['title'] = 'Ошибка!';
- array_push($aRes['msg'], 'Введите ваше имя');
- array_push($aRes['fields'], 'name');
- }
- if (!empty($email) && !isEmail($email)) {
- $aRes['is'] = false;
- $aRes['title'] = 'Ошибка!';
- array_push($aRes['msg'], 'Email заполнен не верно');
- array_push($aRes['fields'], 'email');
- }
- if ($aRes['is']) {
- $site = $_SERVER['SERVER_NAME'];
- $to = 'j-tap@ya.ru';
- $subject = 'Хочу индивидуальную программу';
- $sSubject = 'Squadra - Хочу индивидуальную программу';
- $sHeaders = "Content-type: text/html; charset=utf-8 \r\n";
- $sHeaders .= "From: Squadra <noreply@$site>\r\n";
- $sBody = '<p>Имя: '. $name .'</p>
- <p>Телефон: '. $phone .'</p>
- <p>Компания: '. $company .'</p>
- <p>Email: '. $email .'</p>';
- mail($to, $sSubject, $sBody, $sHeaders);
- $aRes['title'] = 'Спасибо! Ваша заявка принята';
- }
- break;
- }
- echo json_encode($aRes);
- exit;
- }
- function clearField ($data) {
- $data = trim($data);
- $data = stripslashes($data);
- $data = htmlspecialchars($data);
- return $data;
- }
- function isPhone ($phone) {
- $patt = "/^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$/";
- return preg_match($patt, $phone);
- }
- function isEmail ($email) {
- return filter_var($email, FILTER_VALIDATE_EMAIL) !== false;
- }
- ?>
Add Comment
Please, Sign In to add comment