Welcome Guest, Not a member yet? Register   Sign In
File upload validation fails for uploaded rule
#1

Hi everyone.
I am having some problems getting the uploaded validation rule to work with file attachment uploads using the form helper too.

Here is the form I am using in my view file opus_index.php
PHP Code:
<?=$this->extend("layouts/base");?>
<?=$this
->section("content");?>
<h4 id="pif_h4" class="text-center text-capitalize" style="margin-top: 60px;">OPUS DATA PROCESSEING</h4>
<div class="container" style="margin-top: 18px;">
  <div class="container col-7 d-flex justify-content-center">
    <?=form_open_multipart(base_url('opus/process'), ['class' => 'form-horizontal''id' => 'opus_data_load_form']);?>
      <div class="form-group my_fg"><!--Control Point #-->
        <?=form_label('Control Point #:''control_point_num', ['id' => 'control_point_num''class' => 'form-control-label col-sm-5 text-dark']);?>
        <div class="col-sm-12">
            <?=form_input(['type' => 'number''class' => 'form-control''name' => 'control_point_num''value' => set_value('control_point_num''')]);?>
            <span class="invalidFeedback" id="control_point_num_span"><?=displayValidationError($validation'control_point_num')?></span>
        </div>
      </div><!---->
      <div class="form-group"><!--Northing-->
        <?=form_label('Northing:''cp_northing', ['id' => 'cp_northing''class' => 'form-control-label col-sm-5 text-dark']);?>
        <div class="col-sm-12">
            <?=form_input(['type' => 'number''class' => 'form-control''name' => 'cp_northing''step' => '0.0001''value' => set_value('cp_northing''')]);?>
            <span class="invalidFeedback" id="cp_northing_span"><?=displayValidationError($validation'cp_northing')?></span>
        </div>
      </div><!---->
      <div class="form-group"><!--Easting-->
        <?=form_label('Easting:''cp_easting', ['id' => 'cp_easting''class' => 'form-control-label col-sm-5 text-dark']);?>
        <div class="col-sm-12">
            <?=form_input(['type' => 'number''class' => 'form-control''name' => 'cp_easting''step' => '0.0001''value' => set_value('cp_easting''')]);?>
            <span class="invalidFeedback" id="cp_easting_span"><?=displayValidationError($validation'cp_easting')?></span>
        </div>
      </div><!---->
      <!-- <div class="container form-group row"> -->
      <div class="form-group"><!--ORTHO HGT-->
        <?=form_label('ORTHO HGT:''cp_ortho_hgt', ['id' => 'cp_ortho_hgt''class' => 'form-control-label col-sm-5 text-dark']);?>
        <div class="col-sm-12">
            <?=form_input(['type' => 'number''class' => 'form-control''name' => 'cp_ortho_hgt''step' => '0.001''value' => set_value('cp_ortho_hgt''')]);?>
            <span class="invalidFeedback" id="cp_ortho_hgt_span"><?=displayValidationError($validation'cp_ortho_hgt')?></span>
        </div>
      </div><!---->
      <div class="form-group"> <!--Sky CSV-->
        <?=form_label('CSV Data File:''sky_csv_file', ['id' => 'sky_csv_file_upload''class' => 'form-control-label col-sm-8 text-darkcol-form-label text-dark']);?>
          <div class="col-sm-10">
            <?=form_upload(['class' => 'form-control-file''id' => 'sky_csv_file''name' => 'sky_csv_file''accept' => '.csv']);?>
            <?=form_hidden('MAX_FILE_SIZE''67108864');?> <!--64 MB's worth in bytes. Be sure no commas are in the value if changing-->
          </div>
        <span class="invalidFeedback" id="sky_csv_file_span"><?=displayValidationError($validation'sky_csv_file')?></span>
      </div>
      <br>
      <div class="d-flex justify-content-center">
        <div class="col-8 text-center">
        <?=form_label('Submit for Processing''Submit', ['id' => 'sub_process']);?><br>
        <?=form_submit('Submit''Submit', ['class' => 'btn btn-sm btn-outline-primary btn-block active btn-block']);?>
        </div>
      </div>
      <?=form_close();?>
  </div>
</div>
<?=$this->endSection();?>

Note: the displayValidationError() function is a function I have in a custom helper I made for displaying validation errors in the form. (If this helps any?)
Here is the function definition:
PHP Code:
function displayValidationError($validationstring $field) {
 if (isset(
$validation)) {
if (
$validation->hasError($field)) {
return 
$validation->getError($field);
}
} else {
return 
FALSE;
}



In the controller, I have this method where I check for request type and that the submit button was clicked along with these rules for all the form fields:


PHP Code:
public function process() {
$csv_rows = array(); // used to hold the uploaded SKY file CSV data
$data = ['page_title' => 'OPUS PROCESSING',
 
'validation' => NULL];

if (
$this->request->getMethod() == 'post' && !empty('sub_process')) {

$rules = [
'control_point_num' => [
'rules' => 'required',
'errors' => [
 
'required' => 'Control Point is required',
 ],
],
'cp_northing' => [
'rules' => 'required',
'errors' => [
 
'required' => 'Northing Coordinate is required',
 ],
],
'cp_easting' => [
'rules' => 'required',
'errors' => [
 
'required' => 'Easting Coordinate is required',
 ],
],
'cp_ortho_hgt' => [
'rules' => 'required',
'errors' => [
 
'required' => 'ORTHO Height Coordinate is required',
 ],
],
'sky_csv_file' => [
'rules' => 'uploaded[sky_csv_file]|max_size[sky_csv_file,67108864]|ext_in[sky_csv_file,csv]',
'errors' => [
 
'uploaded' => 'SKY CSV file not attached',
 
'max_size' => 'File too big to upload',
 
'ext_in' => 'Must be a CSV file type',
 ],
],
];

//more work here

if ($this->validate($rules)) {
// more work here

} else {
$data['validation'] = $this->validator;
}



But whenever I submit the form with the file attached, I still get the error for no file attached. I am assuming for some reason it's the uploaded rule?

Does anyone know why this isn't passing the uploaded validation?

I even did a var_dump() on the post request object but the file upload field isn't even showing any data... Not sure why.

PHP Code:
var_dump($this->request->getPost());
array(
6) { ["control_point_num"]=> string(3"123" ["cp_northing"]=> string(6"123.33" ["cp_easting"]=> string(6"123.33" ["cp_ortho_hgt"]=> string(6"123.33" ["MAX_FILE_SIZE"]=> string(8"67108864" ["Submit"]=> string(6"Submit" 
Reply


Messages In This Thread
File upload validation fails for uploaded rule - by josh2112o - 11-23-2022, 01:55 PM



Theme © iAndrew 2016 - Forum software by © MyBB