<form id="formVacancy" class="_form">
<input type="file" id="resume"><label for="resume" class="__e"></label>
<a href="javascript:void(0)" class="_btn_ btnB tabstop" data-role="submit" id="formSend">
<span tabindex="-1">Отправить</span>
</a>
</form>
function sendContact2() {
$.ajax({
url: "/wp-admin/admin-ajax.php",
method: 'post',
data: {
action: 'ajax_job2',
name: $("#VlastName1").val(),
name2: $("#VfirstName1").val(),
name3: $("#VsurName1").val(),
phone: $("#Vphone1").val(),
email: $("#VbirthDay1").val(),
namech: $("#namech1").val(),
text: $("#question1").val(),
file: $("#resume")
}
})
.done(function( msg ) {
var a = $('link[rel=canonical]').attr('href');
0 < a.indexOf("/contact/") && (a = "/contact/");
//a = a.replace(/(#.*$)/img, "");
document.location.href = a
})
}
isset($_POST['file']);
if( count( $_POST['file'] ) > 0 ){
$attachment = wp_upload_dir() . basename($_POST['file']['name']);
move_uploaded_file($_POST['file']['tmp_name'], $attachment);
}
// serializefiles
// обрабатываем данные формы
(function($) {
$.fn.serializefiles = function() {
var obj = $(this);
/* ADD FILE TO PARAM AJAX */
var formData = new FormData();
$.each($(obj).find("input[type='file']"), function(i, tag) {
$.each($(tag)[0].files, function(i, file) {
formData.append(tag.name, file);
});
});
var params = $(obj).serializeArray();
$.each(params, function (i, val) {
formData.append(val.name, val.value);
});
return formData;
};
})(jQuery);
// formId = ID отправляемой формы
function sendContact(formId) {
var formData = $(formId).serializefiles();
$.ajax({
type: 'POST',
url: '/wp-admin/admin-ajax.php',
data: formData,
async: false,
cache: false,
contentType: false,
processData: false,
})
.done(function( msg ) {
var a = $('link[rel=canonical]').attr('href');
0 < a.indexOf("/contact/") && (a = "/contact/");
//a = a.replace(/(#.*$)/img, "");
document.location.href = a
})
}
// Отправка формы;
$("#form1").on("submit", function(e){
e.preventDefault();
sendContact("#form1");
return !1;
});