I have a fairly large form that I am using with Formit. I currently have 3 file uploads and I am using formit2file for this portion. I am having major issues with it as it sometimes works and sometimes just redirects to the homepage upon submission. Everytime it plugs along and show progress uploading the files. It seems like it works uploading 3 small pdfs, but with large files it redirects to the homepage (it should go to thank you page), using txt files redirects to homepage, etc. But it is hard to pinpoint what is causing it. There are no errors thrown for example if file size is to large or file type not allowed.
I really need help with this. I need it to upload multiple files, and if there is an error, it should display the error just the same as if a form field wasn't filled out.
I am using REVO 2.0.4-pl2 and formit 1.4.1
Here is the formit2file snippet
<?php
$path; // Path from root that user specifies
$extensions; // allow file extensions
$ext_array = explode(',', $extensions);
// Create path
$basepath = $modx->config['base_path']; // Site root
$target_path = $basepath . $path; // root /assets/upload
//$target_path = '/home/emeraldfound/emeraldfoundation.ca/assets/uploads/';
// Get Filename and make sure its good.
$filename = basename( $_FILES['nomination_file']['name'] );
// Get files extension
$ext = pathinfo($filename, PATHINFO_EXTENSION);
if($filename != '')
{
// Make filename a good unique filename.
// Make lowercase
$filename = mb_strtolower($filename);
// Replace spaces with _
$filename = str_replace(' ', '_', $filename);
// Add timestamp
$filename = date("Ymdgi") . $filename;
// Set final path
$target_path = $target_path . $filename;
if(in_array($ext, $ext_array))
{
if(move_uploaded_file($_FILES['nomination_file']['tmp_name'], $target_path))
{
// Upload successful
//$hook->setValue('nomination_file',$_FILES['nomination_file']['name']);
$hook->setValue('nomination_file',$filename);
return true;
}
else
{
// File not uploaded
$errorMsg = 'File not uploaded.';
$hook->addError('nomination_file',$errorMsg);
return false;
}
}
else
{
// File type not allowed
$errorMsg = 'File not allowed.';
$hook->addError('nomination_file',$errorMsg);
return false;
}
}
else
{
$hook->setValue('nomination_file','');
return true;
}
return true;
Here is my formit call
[[!FormIt?
&hooks=`spam,formit2file,formit2resource,email,FormItAutoResponder,redirect`
&preHooks=`resource2formit`
&path = `assets/uploads/`
&extensions = `jpg,JPG,jpeg,JPEG,doc,docx,pdf,txt,png,zip,mov,avi,mpeg,mp4`
&maxsize = `31457280`
&published=`1`
&template=`2`
&emailTpl=`nominateEmailTpl`
&emailTo=`X`
&emailSubject=`X`
&emailFrom=`X`
&fiarTpl=`nominateEmailTpl`
&fiarSubject=`X`
&fiarToField=`nominator_email`
&fiarFrom=`X`
&resource2formitfields=`parent,pagetitle,nominee,project,nominee_type,
nominee_title,nominee_contact,nominee_position,nominee_department,nominee_organization,nominee_address_type,nominee_address,nominee_city,nominee_province,
nominee_postalcode,nominee_phone,nominee_fax,nominee_email,nominee_website,
nominator_same,nominator_title,nominator_contact,nominator_position,nominator_department,nominator_organization,nominator_address_type,nominator_address,nominator_city,nominator_province,
nominator_postalcode,nominator_phone,nominator_fax,nominator_email,nominee_category,
nomination_summary,nomination_environmental,nomination_commitment,nomination_sharing,nomination_innovation,nomination_sharedfootprints,nomination_worthy,
nomination_file,nomination_file2,nomination_file3,nomination_weblink,
condition_1,condition_2,condition_3,condition_4,condition_name,condition_phone,condition_email,
emerald_hearabout,emerald_other`
&pagetitle=`nominee`
&redirectTo=`80`
]]