Jump to content

File upload via InputfieldFile


Recommended Posts

Hi Guys

I'am trying to add a csv-import for our mailchimp module in processwire. So I added a new InputfieldFieldset["Import Mailchimp-Members via CSV File"] to the InputfieldWrapper["List Members"] which is also added final to the InputfieldForm. Inside the Inputfieldset I added a InputfieldFile with this configuration:

        $fieldsetImport = $this->modules->get("InputfieldFieldset");
        $fieldsetImport->label = "Import Mailchimp-Members via CSV File";
        $fieldsetImport->collapsed = Inputfield::collapsedYes;

        $field = $this->modules->get("InputfieldFile"); 
        $field->name = 'csv_file';
        $field->label = 'CSV File';
        $field->extensions = 'csv txt';
        $field->maxFiles = 1; 
        $field->overwrite = true;
        $field->descriptionRows = 0;
        $field->required = false; 
        $field->description = 
            "The list of field names must be provided as the first row in the Spreadsheet file. " . 
            "UTF-8 compatible encoding is assumed. File must have the extension '.csv' or '.txt' ";

        $field = $this->modules->get("InputfieldSubmit");
        $field->attr("name", "import");
        $field->attr("value", "Import");

When I add a File and the click on import the "executeEdit" Function will be triggered. This function does the processing of the Form. It handles multiple $this->input->post->submitname:

public function executeEdit(){
        if($this->input->post->submit) {

           //other form processing

        if($this->input->post->subscribe) {

           //other form processing

        if($this->input->post->import) {


            if(!$form->getErrors()) {

                $csv_file = $form->get("csv_file")->value;
                if(count($csv_file)) {
                    $csvFile = $csvFile->first();
                    $csvFilename = $csvFile->filename; 
                    echo "No files were found";



        if($this->input->post->createSegment) {

            // other form processing

The processing part of the $this->input->post->import is from the ImportPagesCSV.module from Ryan. But I always get the output "No files were found". What I'm missing?

Link to comment
Share on other sites

  • 3 months later...

I have a very similar situation. I'm trying to upload a CSV file to a custom admin page, created with the Admin Custom Pages module. I've constructed a simple form using the API. When I load the page, the form appears to render correctly, but it doesn't appear to be working 100% correctly.

• Drag and drop isn't working. The browser just offers to open the dragged file. There are no JS errors in the console and it looks as if all the required JS assets are included on the page. If I instead click the "Choose File" button and select a file, it does appear to select a file (if I hover over the "Choose File" button, it displays the selected filename).

• Submitting the form does upload the file, though overwrite isn't working. I get the following error when trying to re-upload the same file:

"Refused file [my filename] because it is already on the file system and owned by a different field."


Link to comment
Share on other sites

  • 1 year later...

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

  • Create New...