Jump to content

Bulk Upload/Import Process module, how to implement InputfieldFile?


hellomoto
 Share

Recommended Posts

I have a process module like so:

  public function execute() {
    $output = 'mad music archive/bulk uploadability management';
    $form = $this->makeForm();

    if($this->input->post->import) $output .= $this->bulkup($form);
    else $output .= $form->render();

    return $output;
  }

  public function ___install() {
    $mkr = new ImportShorthand();
    $p = [[
      'template' => 'admin',
      'parent_id' => 2,
      'name' => self::PGNAME,
      'title' => '[Blaudio] Mgmt',
     ],[ 'process' => $this, ]];
    $mkr->newPage($p);
  }

  public function ___uninstall() {
    $wp = wire('pages');
    $pg = $wp->get('template.id=2, parent.id=2, name='.self::PGNAME);
    if($pg->id) $wp->delete($pg, true);
  }

  private function bulkup($form) {
    if($this->input->post->import) {
      $form->processInput($this->input->post); return;
      if(!$form->getErrors()) {
        $files = $form->get("bla_upload")->value;
        if(count($files)) { return count($files);/*
            $bulkload = $bulk_upload->first();
            //$bulkload->rename("address-import.csv");
            $bulkloadname = $bulkload->filename;*/
        }else{ return "No files were found"; }
        //$this->session->redirect("../edit/?id=$list_id");
      }
    }
  }

  private function makeForm() {

So far, returning early in the bulkup() function, submitting the form with an acceptable file results in this error message: 

Quote

 InputfieldFile: Missing required value (bla_upload)

Upon reloading the page (afresh, without the submitted data; i.e., clicking its link in the nav) this error is displayed within the upload field:

Quote

Missing required value

I'm assuming this is due to the fact that this is a process page. How do I ensure temporary storage? My goal ultimately is to insert a new page for each valid file. 

Thanks much in advance.

Link to comment
Share on other sites

Updated bulkup():

  private function bulkup($form) {
    if($this->input->post->import) {
        $files = $this->input->post->bla_upload;
        if(!count($files)) { return "No files were found.";
        }else{ 
          $list = '';
          foreach($files as $f) {
            $list .= $f . PHP_EOL;
          }
          return count($files)."\n".$list;
        }
    }
  }

Like this it returns:

Quote

2 Doralice Children [Blackstar x Getz_Gilberto].mp3

when I upload just 1 file... it counts 2... and there is (and was before) a directory for the process page's ID in site/assets/files, but it remains empty still.

I'm blue, need a clue.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...