Guest User

Untitled

a guest
Mar 19th, 2018
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. $('form input').tooltip({
  2. trigger: 'manual',
  3. placement: 'bottom',
  4. container: 'body'
  5. }).on('shown.bs.tooltip', function (e) {
  6. $(e.target).on('focus', function () {
  7. $(e.target).tooltip('hide');
  8. })
  9. /*setTimeout(function () {
  10. $(e.target).tooltip('hide');//.removeAttr('data-original-title');
  11. }, 5000)*/
  12. })
  13.  
  14. $('form.form-ajax').submit(function (evt) {
  15. var eForm = $(this);
  16. preloader(eForm);
  17. eForm.find('[data-original-title]').removeAttr('data-original-title');
  18. $.post(eForm.attr('action'), eForm.serialize()).done(function (res) {
  19. preloader(eForm, false);
  20. var oRes = $.parseJSON(res);
  21. //console.info(oRes);
  22. eForm.find('.err').removeClass('err');
  23. if (oRes.is) {
  24. eForm[0].reset();
  25. showMessage(oRes.title, oRes.msg);
  26. } else {
  27. oRes.fields.forEach(function (sField, i) {
  28. var eField = eForm.find('[name='+ sField +']');
  29. eField.addClass('err').attr('data-original-title', oRes.msg[i]);
  30. eField.tooltip('show');
  31. })
  32. }
  33. });
  34. evt.preventDefault();
  35. })
  36.  
  37. function preloader (eElem, is = true) {
  38. var eIconPreloader = $('<i/>');
  39. ePreloader = $('<div class="preloader js-preloader"/>').append(eIconPreloader);
  40. if (is) {
  41. eElem.children().addClass('loading');
  42. eElem.append(ePreloader);
  43. } else {
  44. eElem.children('.js-preloader').remove();
  45. eElem.children().removeClass('loading');
  46. }
  47. }
  48.  
  49.  
  50.  
  51. /* PHP
  52. */
  53. <? if (isset($_POST['type'])) {
  54.  
  55. $aRes = array(
  56. 'is' => true,
  57. 'type' => $_POST['type'],
  58. 'msg' => array(),
  59. 'data' => false
  60. );
  61.  
  62. switch ($_POST['type']) {
  63.  
  64. case 'individual-programm':
  65.  
  66. $aRes['title'] = '';
  67. $aRes['fields'] = array();
  68.  
  69. $name = clearField($_POST['name']);
  70. $phone = clearField($_POST['phone']);
  71. $company = clearField($_POST['company']);
  72. $email = clearField($_POST['email']);
  73. $isAccept = (isset($_POST['accept']));
  74.  
  75. if (!$isAccept) {
  76. $aRes['is'] = false;
  77. $aRes['title'] = 'Ошибка!';
  78. array_push($aRes['msg'], 'Чтобы продолжить, нужно принять условия пользовательского соглашения');
  79. array_push($aRes['fields'], 'accept');
  80. }
  81. if (empty($phone)) {
  82. $aRes['is'] = false;
  83. $aRes['title'] = 'Ошибка!';
  84. array_push($aRes['msg'], 'Введите ваш телефон');
  85. array_push($aRes['fields'], 'phone');
  86. } elseif (!isPhone($phone)) {
  87. $aRes['is'] = false;
  88. $aRes['title'] = 'Ошибка!';
  89. array_push($aRes['msg'], 'Телефон заполнен не верно');
  90. array_push($aRes['fields'], 'phone');
  91. }
  92. if (empty($name)) {
  93. $aRes['is'] = false;
  94. $aRes['title'] = 'Ошибка!';
  95. array_push($aRes['msg'], 'Введите ваше имя');
  96. array_push($aRes['fields'], 'name');
  97. }
  98. if (!empty($email) && !isEmail($email)) {
  99. $aRes['is'] = false;
  100. $aRes['title'] = 'Ошибка!';
  101. array_push($aRes['msg'], 'Email заполнен не верно');
  102. array_push($aRes['fields'], 'email');
  103. }
  104.  
  105. if ($aRes['is']) {
  106. $site = $_SERVER['SERVER_NAME'];
  107. $to = 'j-tap@ya.ru';
  108. $subject = 'Хочу индивидуальную программу';
  109.  
  110. $sSubject = 'Squadra - Хочу индивидуальную программу';
  111. $sHeaders = "Content-type: text/html; charset=utf-8 \r\n";
  112. $sHeaders .= "From: Squadra <noreply@$site>\r\n";
  113. $sBody = '<p>Имя: '. $name .'</p>
  114. <p>Телефон: '. $phone .'</p>
  115. <p>Компания: '. $company .'</p>
  116. <p>Email: '. $email .'</p>';
  117.  
  118. mail($to, $sSubject, $sBody, $sHeaders);
  119.  
  120. $aRes['title'] = 'Спасибо! Ваша заявка принята';
  121. }
  122. break;
  123. }
  124.  
  125. echo json_encode($aRes);
  126.  
  127. exit;
  128. }
  129.  
  130. function clearField ($data) {
  131. $data = trim($data);
  132. $data = stripslashes($data);
  133. $data = htmlspecialchars($data);
  134. return $data;
  135. }
  136. function isPhone ($phone) {
  137. $patt = "/^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$/";
  138. return preg_match($patt, $phone);
  139. }
  140. function isEmail ($email) {
  141. return filter_var($email, FILTER_VALIDATE_EMAIL) !== false;
  142. }
  143. ?>
Add Comment
Please, Sign In to add comment