Hi!
I have a form that creates new pages, with a simple text field and the option to upload an image. When I try to submit the form without uploading a file, it gives me the error “The file is missing” and refers to this (in upload.php in the getkirby/toolkit/lib) as the error:
throw new Error($messages[$code], $code);
I do not receive this error when I write text + upload a file. However, even when I get the error, the submission still goes through successfully.
Weird thing is, it was working perfectly until I transferred the whole site from a localhost on a school computer to the localhost on my desktop computer…did I just pull my harddrive out too soon or what?!
This is my controller:
return function($site, $pages, $page) {
$alert = null;
if(r::is('post') && get('register')) {
if(!empty(get('website'))) {
// lets tell the bot that everything is ok
go($page->url());
exit;
}
$data = array(
'title' => esc(get('title')),
'text' => esc(get('text')),
'date' => date('Y-m-d'),
'time' => time()
);
$rules = array(
'text' => array('required'),
);
$messages = array(
'text' => 'Please enter text',
);
if($invalid = invalid($data, $rules, $messages)) {
$alert = $invalid;
} else {
try {
$p = $page->children()->create(str::slug($data['title']) , 'floor', $data);
$upload = new Upload($p->root() . DS . '{safeFilename}', array('input' => 'file'));
$success = 'Success.';
$data = array();
} catch(Exception $e) {
echo 'Failed: ' . $e->getMessage();
}
}
}
return compact('alert', 'data', 'success');
Thanks in advance!