This is a project that works on another opensuse 13.1. On my laptop, also opensuse 13.1, i get an undefined index for the input "census". I'm afraid to copy back up to the server, as it works with the same code!
the last line i show for update.php is the first undefined index I get for 'census'. the var_dumps both return NULL. However, I can use console.log on proposal.php to dump the census variable to console, and it's correct. It will show the filename of the file. Why isn't it getting passed to the second php script?
I have enctype set in the ajax call and in the form tag.
initial proposal.php:
<script>
$(document).ready(function(){
$('#subreq').click(function(){
$("#mainform").hide();
$("#prevreqs").show();
});
$('#newreq').click(function(){
$("#mainform").show();
$("#prevreqs").hide();
});
$('input[type="radio"]').click(function(){
if($(this).attr("value")=="1099"){
$("#mecprod").hide();
$("#tprod").show();
$("#industry").show();
}
if($(this).attr("value")=="W2"){
$("#mecprod").show();
$("#tprod").show();
$("#industry").hide();
$('[name=indtype]').prop('checked',false);
}
if($(this).attr("value")=="trucking"){
$("#trucktype").show();
}
if($(this).attr("value")=="realtor" || ($(this).attr("value")=="other")){
$("#trucktype").hide();
$('[name=transtype]').prop('checked',false);
}
if($(this).attr("value")=='other'){
$("#otherinfo").show();
}
});
$('form#proposal-request').submit( function(e) {
e.preventDefault();
var cname = $('#cname').val();
var caddress = $('#caddress').val();
var ctype = $('#ctype').val();
var ein = $('#ein').val();
var wellmec = $('#wellmec').val();
var tmec = $('#tmec').val();
var dmec = $('#dmec').val();
var census = $('#census').val();
var std_comp = $('#std_comp');
var notes = $('#notes');
var emptype = $('input:radio[name=emptype]:checked').val();
var transtype = $('input:radio[name=transtype]:checked').val();
if ($('input:radio[name=indtype]:checked').val() == 'other'){
var indtype = $('#otherind').val();
} else {
var indtype = $('input:radio[name=indtype]:checked').val();
}
if (cname == '' || caddress == '' || ein == '') {
$('#error').show().children('span').html('Compnay Name, Address and EIN are required.');
return false;
} else if ($('input:radio[name=emptype]:checked').val() == 'W2' && $('#wellmec').prop('checked') == false && $('#tmec').prop('checked') == false && $('#dmec').prop('checked') == false) {
$('#error').show().children('span').html('At least one MEC product must be selected.');
return false;
} else if (census == '') {
$('#error').show().children('span').html('A Census Must Be Uploaded To Continue.');
return false;
} else if (emptype == '') {
$('#error').show().children('span').html('Please select 1099 or W2.');
return false;
} else {
$.ajax({
url: 'assets/update.php',
type: 'POST',
enctype: 'multipart/form-data',
data: new FormData(this),
cache: false,
contentType: false,
processData: false,
success: function(response) {
if (response == '1') {
$('#error').hide();
$('#success').show();
$('#cname').val('');
$('#caddress').val('');
$('#ctype').val('');
$('#ein').val('');
$('#fname').val('');
$('#lname').val('');
$('#bemail').val('');
$('[name=emptype').prop('checked',false);
$('#wellmec').prop('checked', false);
$('#tmec').prop('checked', false);
$('#dmec').prop('checked', false);
$('#census').replaceWith($('#census').val('').clone(true));
$('#std_comp').val('');
$('#notes').val('');
$('[name=truck]').prop('checked',false);
$('[name=indtype]').prop('checked',false);
$('#otherind').val('');
$moveon = window.setTimeout(function() {
$('#success').hide();
}, 5000);
} else {
$('#error').show().children('span').html(response);
}
}
});
}
});
$('.close').click(function() {
$(this).parent().hide();
})
});
<form method="POST" id="proposal-request" >
<div class="form-group">
<h4><b>Upload Census File:</b></h4>
<input type="file" id="census" name="census" />
<p class="help-block">A census file is required to continue.</p>
</div>
</form>
now update.php
var_dump($_POST);
var_dump($_FILES['census']);
try {
$cname = filter_input(INPUT_POST, 'cname', FILTER_SANITIZE_STRING);
$caddress = filter_input(INPUT_POST, 'caddress', FILTER_SANITIZE_STRING);
$ctype = filter_input(INPUT_POST, 'ctype', FILTER_SANITIZE_STRING);
$ein = filter_input(INPUT_POST, 'ein', FILTER_SANITIZE_STRING);
$wellmec = (!empty($_POST['wellmec']) &&$_POST['wellmec'] == '1' ? 1 : 0);
$tmec = (!empty($_POST['tmec']) && $_POST['tmec'] == '1' ? 1 : 0);
$dmec = (!empty($_POST['dmec']) &&$_POST['dmec'] == '1' ? 1 : 0);
$broker_id = $_SESSION['id'];
$std_comp = filter_input(INPUT_POST, 'std_comp', FILTER_SANITIZE_STRING);
$notes = filter_input(INPUT_POST, 'notes', FILTER_SANITIZE_STRING);
$emptype = filter_input(INPUT_POST, 'emptype', FILTER_SANITIZE_STRING);
$indtype = filter_input(INPUT_POST, 'indtype', FILTER_SANITIZE_STRING);
$transtype = filter_input(INPUT_POST, 'transtype', FILTER_SANITIZE_STRING);
$Database->sqlQuery('SELECT email, fname, lname FROM brokers WHERE id = :broker_id', array(':broker_id' => $broker_id));
$broker = $Database->sth->fetch();
$allowedExts = array('csv', 'xls', 'xlsx');
$temp = explode(".", $_FILES["census"]["name"]);