I will need to restrict this video field to just .mp4. I have found it allows upload of .mov files but does not display them correctly. It displays them as a link instead of playing them in place..
I changed the code to use my cred form id and also fixed the typo on line 15 but this is still allowing .mov files to be uploaded.
Here is my modified code:
// validate video
function video_field_validation($field_data, $form_data) {
//field data are field values and errors
list($fields,$errors)=$field_data;
//validate if specific form
if ($form_data['id']==258) {
//allowed video extensions
$allowed_types = array('video/mp4');
// uploaded image extension
$type = $fields['wpcf-video']['field_data']['type'];
// checking allowed extension with uploaded image extension
if (!in_array($type,$allowed_types)){
//set error message
$errors['wpcf-video'] = 'Please upload a mp4 video';
}
}
//return result
return array($fields,$errors);
}
add_filter('cred_form_ajax_upload_validate','video_field_validation',10,2);
Would also like to restrict size of upload to 20mb.
Could this be added into the JS editor of the cred form instead of as a function?
Hello. Thank you for contacting the Toolset support.
I'm not sure why you want to use the video field as when you use video field, the video file it self will be uploaded to the server and cost you your server space.
Instead of that, why dont you try to use the emended field where you should just upload the video URL and try to display it or maybe another possible field type is use URL field that holds the video URL that is uploaded to any third-party video site like youtube and add the link only.
You can even create a test site on http://www.discover-wp.com and install any of our reference site and play with field types to know how it works and later decide with what field type URL, Embedded or Video you want to go with.
I suggest first of all you first decide with what field type you want to go ahead and then we will move on the validating the file type and size using Forms.
Hi Minesh, This audience isn't very tech savvy and explaining YouTube to them won't work. I was planning to set a file size cap as the videos should only be 15 seconds. Not ideal I know but most of them won't make a video anyway. So just need to restrict field to .mp4 and file size to 15mb.
Here's the current code I'm using which is not working. The regular video validation is happening in that I can't upload a jpg or a mp3 but I can still upload a .mov. I need this to allow only mp4 files of 15 mb or lower.
// validate video
function video_field_validation($field_data, $form_data) {
//field data are field values and errors
list($fields,$errors)=$field_data;
//validate if specific form
$form_ids = array(258,346);
if ( in_array($form_data['id'], $form_ids)) {
//allowed video extensions
$allowed_types = array('video/mp4');
// uploaded image extension
$type = $fields['wpcf-video']['field_data']['type'];
// checking allowed extension with uploaded image extension
if (!in_array($type,$allowed_types) ) {
//set error message
$errors['video'] = 'Please upload a mp4 video';
}
}
//return result
return array($fields,$errors);
}
add_filter('cred_form_ajax_upload_validate','video_field_validation',10,2);
If that does not help, please share problem URL where you added the form as well as admin access details.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
// validate video
function ied_video_field_validation($field_data, $form_data)
{
// Field data are field values and errors
list($fields,$errors)=$field_data;
// Run the rest of code for this CRED ONLY and IF there is a file uploaded.
$form_ids = array(258,346);
if ( in_array($form_data['id'], $form_ids) && (!empty($_POST['wpcf-video']) ) ) {
// Retrieve file type
$file_type_uploaded=$_FILES['wpcf-video']['type'];
// Retrieve file size
$file_size_uploaded=$_FILES['wpcf-video']['size'];
// Validate files uploaded, make sure its MP4 file type AND not more than 15MB
if (!( ('video/mp4' == $file_type_uploaded) && ($file_size_uploaded < 5000000) )) {
$errors['video']='Please upload a mp4 video that is 15MB or less.';
}
}
//return result
return array($fields,$errors);
}
add_filter('cred_form_validate','ied_video_field_validation',10,2);