Guest User

Untitled

a guest
Feb 17th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. function submit_form(e) {
  2. var $form = $(e.target),
  3. $btn = $form.find('button'),
  4. btn_text = $btn.text();
  5. $.ajax({
  6. // url: '/',
  7. data: $form.serialize(),
  8. dataType: 'json',
  9. type: 'POST',
  10. beforeSend: function() {
  11. $('#contact_fail .alert-inner').empty();
  12. $('#contact_fail').hide();
  13. $btn.attr('disabled', 'disabled').addClass('btn-disabled').css('cursor', 'not-allowed').text('Отправляется...');
  14. },
  15. success: function(result) {
  16. if (typeof result.success == 'undefined') {
  17. // form is not valid, display errors
  18. for (var x in result) {
  19. $('#contact_fail .alert-inner').append('<p>' + result[x] + '</p>');
  20. }
  21. $('#contact_fail').fadeIn();
  22. }
  23. else {
  24. // form sent successfully and without errors
  25. $('#contact_success').fadeIn(700, function() {
  26. var $this = $(this);
  27. setTimeout(function() {
  28. $this.fadeOut();
  29. }, 5000);
  30. });
  31. }
  32. },
  33. complete: function() {
  34. $btn.removeAttr('disabled', 'disabled').removeClass('btn-disabled').css('display', 'none').html(btn_text);
  35. },
  36. error: function(jqXHR, textStatus, errorThrown) {
  37. switch (jqXHR.status) {
  38. case 404:
  39. alert("Мы сожалеем... Файл который вы ищете не найден :(");
  40. break;
  41. case 200, 500:
  42. $('#contact_fail .alert-inner').append("<p>Ой ой, что то пошло не так, и мы не можем отправить ваше сообщение :(</p>");
  43. $('#contact_fail').fadeIn();
  44. console.log(jqXHR, textStatus, errorThrown);
  45. break;
  46. default:
  47. console.log(jqXHR, textStatus, errorThrown);
  48. }
  49. }
  50. });
  51. }
  52.  
  53. <?php
  54. if (Core::moduleIsActive('form'))
  55. {
  56. ob_start();
  57. $oForm = Core_Entity::factory('Form', '21');
  58. $Form_Controller_Show = new Form_Controller_Show($oForm);
  59. $Form_Controller_Show
  60. ->values($_POST + $_FILES)
  61. // 0 - html, 1- plain text
  62. ->mailType(0)
  63. ->mailXsl(
  64. Core_Entity::factory('Xsl')->getByName('ПисьмоКураторуФормыВФорматеHTML')
  65. )
  66. ->mailFromFieldName('***@car-carych.ru')
  67. ->process();
  68. $data = ob_get_clean();
  69. $Form_Controller_Show
  70. ->xsl(
  71. Core_Entity::factory('Xsl')->getByName('ОтобразитьФормуНаГлавной')
  72. )
  73. ->show();
  74. echo json_encode( $data );
  75. }
  76. ?>
  77.  
  78. <?php
  79. if (Core::moduleIsActive('form'))
  80. {
  81. ob_end_clean();
  82. ob_start();
  83. $oForm = Core_Entity::factory('Form', '21');
  84. $Form_Controller_Show = new Form_Controller_Show($oForm);
  85. $Form_Controller_Show
  86. ->values($_POST + $_FILES)
  87. // 0 - html, 1- plain text
  88. ->mailType(0)
  89. ->mailXsl(
  90. Core_Entity::factory('Xsl')->getByName('ПисьмоКураторуФормыВФорматеHTML')
  91. )
  92. ->mailFromFieldName('***@car-carych.ru')
  93. ->process();
  94. $Form_Controller_Show
  95. ->xsl(
  96. Core_Entity::factory('Xsl')->getByName('ОтобразитьФормуНаГлавной')
  97. )
  98. ->show();
  99. $data = ob_get_clean();
  100. echo json_encode( $data );
  101. die();
  102. }
  103. ?>
Add Comment
Please, Sign In to add comment