Cannot submit a form with the 'Upload' File Type
Created 6 years ago by adammckennaI am building a form wherein a user can upload a CV in a .pdf, .doc or .docx format. The form has four fields, three of which are simple text fields. When populating the three text fields and submitting, the form works fine. However, when including the fourth field, an Upload field, the form does not submit (i.e. the form handler is not ran) and the page simply reloads. I cannot generate an error message or anything similar, so I have no idea how to proceed or any idea of why this error is occurring.
Any guidance would be vastly appreciated!
My Form Builder:
<?php namespace Hbi\MainTheme\UploadCV;
use Anomaly\FilesModule\Folder\Contract\FolderRepositoryInterface;
use Anomaly\Streams\Platform\Ui\Form\FormBuilder;
use Illuminate\Http\Request;
use League\Flysystem\MountManager;
class UploadCVFormBuilder extends FormBuilder
{
protected $handler = UploadCVFormHandler::class;
/**
* The form fields.
*
* @var array|string
*/
protected $fields = [
'name' => [
'type' => 'anomaly.field_type.text',
'label' => 'Name',
'instructions' => false,
'placeholder' => 'e.g. Joe Bloggs...',
'required' => true
],
'email' => [
'type' => 'anomaly.field_type.text',
'label' => 'Email',
'instructions' => false,
'placeholder' => 'e.g. joe.bloggs@domain.com...',
'required' => true
],
'cv' => [
'label' => 'Upload your CV (.pdf, .doc, .docx; 2mb max)',
'instructions' => false,
'warning' => 'File must be a PDF',
'type' => 'anomaly.field_type.upload',
'config' => [
'folder' => 'slug',
'mimes' => ['pdf']
]
],
'telephone' => [
'type' => 'anomaly.field_type.text',
'label' => 'Telephone',
'instructions' => false,
'placeholder' => 'e.g. (+44) 7123 456 789...',
'required' => true
],
];
/**
* Fields to skip.
*
* @var array|string
*/
protected $skips = [];
/**
* Additional validation rules.
*
* @var array|string
*/
protected $rules = [];
/**
* The form actions.
*
* @var array|string
*/
protected $actions = [];
/**
* The form buttons.
*
* @var array|string
*/
protected $buttons = [];
/**
* The form options.
*
* @var array
*/
protected $options = [
'form_view' => 'theme::partials/form'
];
/**
* The form sections.
*
* @var array
*/
protected $sections = [];
/**
* The form assets.
*
* @var array
*/
protected $assets = [];
}
My Form Handler
<?php namespace Hbi\MainTheme\UploadCV;
use App\Mail\UploadCV;
use App\Mail\UploadCVConfirmation;
use Illuminate\Support\Facades\Mail;
class UploadCVFormHandler
{
/**
* @param UploadCVFormBuilder $builder
*/
public function handle(UploadCVFormBuilder $builder)
{
dd('hit');
// still need to build the logic
}
}
How the form is used in the view:
{{ form('upload-cv').get().getContent()|raw }}
Ah I see! Thanks for a quick response. I'd have a look at that article - I realised my syntax was slightly incorrect, but I was using the multipart form data.
Unfortunately the same error is occurring! I don't suppose you know of any example packages that may have faced this problem before? If so I could perhaps peruse their code to figure out the best implementation.
Thanks again 😄
This is something I hope to automate soon cause it's tricky! But check this tidbit out in the docs: https://pyrocms.com/documentation/upload-field-type/1.2/usage/setting-values#multipart-form-data