fork download
  1. <div class="r" id="contact_index_form">
  2.  
  3. <div class="bs-callout bs-callout-warning hidden">
  4. <h4>Niestety, nie wszystko jest wypełnione poprawnie!</h4>
  5. </div>
  6.  
  7. <div class="bs-callout bs-callout-info hidden">
  8. <h4>Świetnie, wszystko ok!</h4>
  9. </div>
  10. <?php
  11.  
  12. // if you want only logged in users to access this function use this hook
  13. add_action('wp_ajax_email_form_submit', 'send_email_form');
  14.  
  15. // if you want none logged in users to access this function use this hook
  16. add_action('wp_ajax_nopriv_email_form_submit', 'send_email_form');
  17.  
  18. // if you want both logged in and anonymous users to get the emails, use both hooks above
  19.  
  20.  
  21. function send_email_form() {
  22.  
  23. $form_errors = array();
  24.  
  25. if( isset($_POST['submit_form']) ) {
  26.  
  27. $name = $_POST['fullname'];
  28. $email = $_POST['email'];
  29. $message = $_POST['message'];
  30. $file = $_POST['file_field'];
  31.  
  32. $subject = 'Z formularza na stronie';
  33.  
  34. $content = "<html>
  35. <head>
  36. <style>
  37. h3 {
  38. text-transform: uppercase;
  39. padding: 0 0 15px 0;
  40. margin: 0;
  41. font-size: 16px;
  42. }
  43. h4 {
  44. font-size: 12px;
  45. line-height: 16px;
  46. padding: 0;
  47. margin: 10px 0 0 0;
  48. font-weight: 800;
  49. }
  50. p {
  51. font-size: 12px;
  52. line-height: 16px;
  53. padding: 0;
  54. margin: 0;
  55. }
  56. </style>
  57. </head>
  58. <body>
  59. <h4>WIADOMOŚĆ Z FORMULARZA NA STRONIE</h4>
  60. <h4>NADAWCA: </h4>
  61. <p>$name, $email</p>
  62. <h4>TREŚĆ: </h4>
  63. <p class='message'>$message</p></br>
  64. </body>
  65. </html>";
  66.  
  67. foreach ($fields as $field) {
  68. if (isset($_POST[$field])) $posted[$field] = stripslashes(trim($_POST[$field])); else $posted[$field] = '';
  69. }
  70.  
  71. $errors = array_filter($form_errors);
  72.  
  73. if (empty($errors)) {
  74. if ( ! function_exists( 'wp_handle_upload' ) ) {
  75. require_once( ABSPATH . 'wp-admin/includes/file.php' );
  76. }
  77.  
  78. $uploadedfile = $_FILES['attachmentFile'];
  79. $upload_overrides = array( 'test_form' => false );
  80. $movefile = wp_handle_upload( $uploadedfile, $upload_overrides );
  81.  
  82. if ( $movefile && ! isset( $movefile['error'] ) ) {
  83. $movefile['url'];
  84. }
  85.  
  86. $to = get_option('admin_email');
  87. $attachments = array($movefile['file']);
  88.  
  89. $headers = array('Content-Type: text/html; charset=UTF-8',
  90. 'From: '.$name.' <'.$email.'>',
  91. 'Reply-To: '.$name.' <'.$email.'>');
  92.  
  93. $success = wp_mail($to , $subject , $content , $headers , $attachments);
  94. return wp_send_json($success);
  95.  
  96.  
  97.  
  98. }
  99. }
  100.  
  101. die();
  102. }
  103.  
  104.  
  105. ?>
  106.  
  107. <div id="message_ok">Y</div>
  108. <div id="message_error">X</div>
  109.  
  110. <form id="index_form" action="email_form_submit" method="post" enctype="multipart/form-data">
  111.  
  112. <span class="field_50">
  113. <label>Twoje imię i nazwisko</label>
  114. <input type="text"
  115. name="fullname"
  116. value="<?php isset( $_POST["fullname"] ) ? esc_attr( $_POST["fullname"] ) : '' ?>"
  117. required>
  118. </span>
  119.  
  120.  
  121. <span class="field_50">
  122. <label>Twój adres e-mail</label>
  123. <input type="email"
  124. name="email"
  125. value="<?php isset( $_POST["email"] ) ? esc_attr( $_POST["email"] ) : '' ?>"
  126. required>
  127. </span>
  128.  
  129. <span class="field_100">
  130. <label>Twoja wiadomość</label>
  131. <textarea name="message"
  132. required><?php isset( $_POST["message"] ) ? esc_attr( $_POST["message"] ) : '' ?></textarea>
  133. </span>
  134.  
  135. <div class="send_file">
  136. <p>Jeżeli chcesz, możesz dołączyć dodatkowe pliki spakowane w jedno archiwum *.zip (max. 20mb).</p>
  137. <div class="choose_file">
  138.  
  139. <label for="file-upload_1" class="custom-file-upload">wskaż plik </label>
  140.  
  141. <input
  142. id="file-upload_1"
  143. class="file-upload"
  144. type="file"
  145. name="attachmentFile"
  146. value="<?php isset( $_POST["file_field"] ) ? esc_attr( $_POST["file_field"] ) : '' ?>"
  147. accept="application/zip"
  148. data-parsley-max-file-size="20480">
  149.  
  150. <button id="btn-file-reset_1" class="btn-file-reset" type="button"></button>
  151. </div>
  152.  
  153. <b><label id="file-name_1" class="file-name"></label></b>
  154. <script>
  155. // wypisuje nazwę pliku
  156. $("#file-upload_1").change(function() {
  157. $("#file-name_1").text(this.files[0].name);
  158. });
  159. // resetuje wybrany plik
  160. $('#btn-file-reset_1').on('click', function(e) {
  161. var $el = $('#file-upload_1');
  162. $el.wrap('<form>').closest('form').get(0).reset();
  163. $el.unwrap();
  164. $("#file-name_1").text("");
  165. });
  166.  
  167. </script>
  168.  
  169. </div>
  170.  
  171. <span class="submit_field">
  172. <input
  173. id="submit"
  174. name="submit_form"
  175. type="submit"
  176. value="Wyślij formularz">
  177. </span>
  178.  
  179.  
  180. </form>
  181. </div>
  182.  
  183. <script>
  184. $(function() {
  185. $('#index_form').parsley().on('field:validated', function() {
  186. var ok = $('.parsley-error').length === 0;
  187. $('.bs-callout-info').toggleClass('hidden', !ok);
  188. $('.bs-callout-warning').toggleClass('hidden', ok);
  189. })
  190. .on('form:submit', function() {
  191. return true;
  192. });
  193. });
  194.  
  195. window.Parsley.addValidator('maxFileSize', {
  196. validateString: function(_value, maxSize, parsleyInstance) {
  197. if (!window.FormData) {
  198. alert('You are making all developpers in the world cringe. Upgrade your browser!');
  199. return true;
  200. }
  201. var files = parsleyInstance.$element[0].files;
  202. return files.length != 1 || files[0].size <= maxSize * 1024;
  203. },
  204. requirementType: 'integer',
  205. messages: {
  206. pl: 'Wybierz plik nie większy niż 20mb.'
  207. }
  208. });
  209.  
  210.  
  211.  
  212. $(document).on('submit', '#index_form', function (event) {
  213.  
  214. event.preventDefault();
  215. var formData = $('#index_form').serialize();
  216. $.ajax({
  217. url: $('#index_form').attr('action'),
  218. type: 'POST',
  219. data: {
  220. action: 'email_form_submit',
  221. },
  222. success: function() {
  223. $('#message_ok').slideDown(400);
  224. },
  225. error: function() {
  226. $('#message_error').slideDown(400);
  227.  
  228. }
  229. });
  230.  
  231. });
  232.  
  233.  
  234.  
  235. </script>
Runtime error #stdin #stdout #stderr 0.01s 82880KB
stdin
Standard input is empty
stdout
<div class="r" id="contact_index_form">

                    <div class="bs-callout bs-callout-warning hidden">
                        <h4>Niestety, nie wszystko jest wypełnione poprawnie!</h4>
                    </div>

                    <div class="bs-callout bs-callout-info hidden">
                        <h4>Świetnie, wszystko ok!</h4>
                    </div>
    
stderr
PHP Fatal error:  Uncaught Error: Call to undefined function add_action() in /home/11e65R/prog.php:13
Stack trace:
#0 {main}
  thrown in /home/11e65R/prog.php on line 13