This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

CricciDisk
CricciDisk

Hello once again, Team October! I hope everyone is doing well and having a wonderful start to 2021. :)

I have revisited my company's website redesign after having shelved it for several months, and I'm unfortunately at another impasse. The big idea is that I have a "project submission" frontend form that allows visitors to enter some order and estimate request details alongside the option to upload a file for the project. The file will be validated to be several specific types pertaining to our industry, including PDFs, PSDs, INDDs, etc.

The form information as well as the file will: (1) save to the backend into our Builder plugin called "Project Submissions", and (2) email to our team of CSRs with a link to the uploaded file. The file upload would ideally appear as a link to the absolute file path on both the submission on the backend as well as the email so the CSR can click it and review/download the file.

After much review of the OctoberCMS documentation as well as several YouTube tutorials, I'm stuck: I'm able to have all of the form's text content submit to both the backend and to the email template, but I'm not able to get the file to upload to the development server or attach to the backend. I've even checked the "public" upload directory to make sure the files weren't hiding out anywhere--no luck. There are no errors displayed during the submission process as either popups or backend log errors.

The troublesome fieldname/entry in the code below is "artworkupload".

Here's a link to an imgur gallery with what I see on the development server (no recent activity related to my upload), the entry on the backend of the database, as well as what happens when I click on the "File upload" 0 bytes link on the backend: https://imgur.com/a/Vc7ljS0

Stripped to the essentials for the request, here's my "default.htm" file in the builder plugin...:

<form id="projectSubmissions" data-request="onSend" enctype="multipart/form-data" data-request-files data-request-flash> 
<input type="hidden" name="_handler" value="onSend">
{{ form_token() }}
{{ form_sessionKey() }}
<!-- Project Artwork Segment -->
<div id="artworkBlock" class="orderblock-container">
    <div class="input-chunk">
        <label>Upload your Artwork!</label> <br>
        <input type="file" name="artworkupload" accept="image/*,.pdf, .ai, .eps, .psd, .zip, .doc, .docx, .xls, .xlsx, .txt, .csv">
    </div>
</div>

<!-- Submission Segment -->
<div id="submitBlock" class="orderblock-container">
    <div class="orderblock">
        <h1>Ready to send your request?</h1>
    </div>
    <div class="orderblock-details">
        <div class="input-chunk"> 
            <button class="arrow-link" type="submit" data-attach-loading>Submit Form</button>

            <div class="statusbox success invisible fineprint">
                <p>Thank you for your submission! We will review your request and respond as soon as possible.</p>
            </div>

            <div class="statusbox loading invisible fineprint">
                <p>Please wait while your submission processes. This may take several minutes if uploading any files, especially if you are on a slower network connection. Do not close your browser or leave this web page.</p>
            </div>

            <div class="statusbox error invisible fineprint">
                <p>Unfortunately, there was a problem with your submission. Please review any highlighted information above and try again in several minutes. If the problem persists, please let us know via phone or email.</p>
            </div>  
        </div>     
    </div>     
</div>
</form>

(Again stripped to the essentials for the help request), The plugin's component...:

<?php namespace Mccabes\ProjectSubmissions\Components;

use Cms\Classes\ComponentBase;
use Mccabes\ProjectSubmissions\Models\Project;
use System\Models\File;
use Input;
use Mail;
use Validator;
use ValidationException;
use Redirect;

class ProjectSubmissions extends ComponentBase
{
    public function componentDetails() {
        return [
            'name' => 'Project Submission Form',
            'description' => 'MPG Project Form'
        ];
    }

    public function onSend() {

        $data = post();

        $rules = [               
        ];

        $validator = Validator::make($data, $rules);

        if($validator->fails()) {
            throw new ValidationException($validator);

        } else {
            // Save to Backend
            $project = new Project();
            $project->artworkupload= Input::File('artworkupload');
            $project->save();

            // Sending notification email
            $vars = Input::all();

            Mail::send('mccabes.generalcontact::mail.message', $vars, function($message) {

                $message->to('EMAIL@EMAIL.COM', 'EMAIL RECIPIENT');
                $message->subject('Hey! New Project Request submitted through our website');

            }); 
        }
    }    
}

The Model...:

<?php namespace Mccabes\ProjectSubmissions\Models;

use Model;
use System\Models\File;

/**
* Model
*/
class Project extends Model
{
    use \October\Rain\Database\Traits\Validation;

    /**
    * @var string The database table used by the model.
    */
    public $table = 'mccabes_projectsubmissions_';

    /**
    * @var array Validation rules
    */
    public $rules = [
    ];

    public $attachOne = [
        'artworkupload' => 'System\Models\File'
    ];
}

And lastly, the particular spot I have "artworkupload" in fields.yaml...:

artworkupload:
    label: 'File upload'
    span: auto
    mode: file
    useCaption: 0
    thumbOptions:
        mode: crop
        extension: auto
    type: fileupload

BONUS POINTS if I can make this work with multiple files. SUPER BONUS POINTS if there's a way to have the filenames maintain their original upload names. :)

I greatly appreciate any help toward this--this is thankfully the last step in a long web development/learning journey for this project. :)

Last updated

mjauvin
mjauvin

Make sure you use 1.0.471 or branch 1.1 as there was a bug with file uploads in prior versions.

CricciDisk
CricciDisk

This did the trick! Thank you so much. :)

1-3 of 3

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.