Skip Navigation

[Resolved] What filetypes are accepted by the video field?

This support ticket is created 2 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 6 replies, has 2 voices.

Last updated by JEN 2 years, 3 months ago.

Assisted by: Minesh.

Author
Posts
#2268787

JEN

I am trying to find out what filetypes are accepted by the video field but cannot find this information in the documentation so asking here.

What filetypes are accepted by the video field?

#2268807

JEN

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 have tried the instructions on this thread:
https://toolset.com/forums/topic/video-custom-fields-not-block-pptxls-upload-2/

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?

#2269487

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

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.

Please check the following link if that help:
- https://toolset.com/course-lesson/youtube-videos-with-advanced-options/#displaying-a-video-with-url-coming-from-a-custom-field

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.

#2271569

JEN

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.

#2271691

JEN

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);

Thank you!

#2272149

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ok.

What if you try to use the validation hook "cred_form_validate" instead of "cred_form_ajax_upload_validate":
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

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.

#2273275

JEN

Figured out a solution for this by following another post: https://toolset.com/forums/topic/file-upload-validation/

Working code:

// 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);
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.