I have the following error when I upload an excel file to the server:
Call to a member function prepare () on a non-object in ...
I show you my file code.
subrile.phtml
<div class="modal-body">
<?php
$form = $this->form;
$form->prepare();
$form = $this->form;
$form->setAttribute('action', $this->url('tributaria/default', array('controller' => 'index', 'action' => 'subirarchivo')));
$form->prepare();
echo $this->form()->openTag($form);
?>
<div class="row">
<span class="col-sm-3 control-label"><?php echo $this->formLabel($form->get('file')); ?></span>
<div class="col-sm-9"><?php echo $this->formFile($form->get('file')); ?></div>
</div>
<div class="text-center" style="background-color: #f8efc0; padding: 8px">
<b>ATENCIÓN:</b><br> La versión del archivo EXCEL debe ser mínimo MICROSOFT EXCEL 2007
</div>
<div class="text-center" style="background-color: #f8efc0; padding: 8px">
Formato de columnas del archivo Excel<br> <b>[ITEM] [CARNET_IDENTIDAD] [NOMBRE_FUNCIONARIO] [DIAS_NO_TRABAJADOS] [DIAS_HABILES] [DIAS_TRABAJADOS]</b>
</div>
<a href="/data/formato.xlsx" >Descargar Plantilla</a>
<div class="modal-footer" style="background-color: #f0f0f0">
<?php echo $this->formElement($form->get('Registrar')) ?>
<button type="button" class="btn default btn-xs" data-dismiss="modal"><?php echo $this->idTributaria == '0' ? 'Cancel' : 'Cerrar' ?></button>
</div>
<?php echo $this->form()->closeTag($form); ?>
</div>
javascript fragment
<script type="text/javascript">
jQuery(document).ready(function () {
handleFormBases();
});
function handleFormBases()
{
var form1 = $('#frmTributaria');
var error1 = $('.alert-danger', form1);
var success1 = $('.alert-success', form1);
form1.validate({
errorElement: 'span', //default input error message container
errorClass: 'help-block', // default input error message class
focusInvalid: false, // do not focus the last invalid input
ignore: "",
rules: {
file: {
required: true,
extension: "xls|xlsx",
},
},
messages: {// custom messages for radio buttons and checkboxes
file: {
required: "Debe cargar un archivo valido de excel",
extension: "Debe cargar un archivo valido de excel",
},
},
invalidHandler: function (event, validator) { //display error alert on form submit
success1.hide();
error1.show();
App.scrollTo(error1, -200);
},
highlight: function (element) { // hightlight error inputs
$(element)
.closest('.form-group').addClass('has-error'); // set error class to the control group
},
unhighlight: function (element) { // revert the change done by hightlight
$(element)
.closest('.form-group').removeClass('has-error'); // set error class to the control group
},
success: function (label) {
label
.closest('.form-group').removeClass('has-error'); // set success class to the control group
},
submitHandler: function (form) {
//alert("aaaaa");
ajaxEnviar(form, '/tributaria/index/index', '#result');
}
});
}
function ajaxEnviar(form, url, div)
{
$('#modal_subirarchivo').modal('hide');
var formData = new FormData(form);
$.ajax({
type: $(form).attr('method'),
url: $(form).attr('action'),
cache: false,
contentType: false,
processData: false,
data: formData,
mimeType: "multipart/form-data",
dataType: "json",
success: function (data)
{
if (data.respuesta)
{
jQuery(div).load(url);
toastr.success(data.mensaje, 'SUCCESS');
} else {
toastr.error(data.mensaje, 'ERROR');
}
},
error: function (jqXHR, status, error) {
alert(error);
toastr.error('OCURRRIO UN ERROR AL EJECUTAR LA PAGINAss', 'ERROR');
},
});
}
I was doing tests and it does not enter the success
of ajax, it goes straight to the error.