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