Problem: I would like to validate the file type of a file uploaded using CRED. Only PDFs should be allowed.
Solution:
Add the following code to functions.php:
function my_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']==138) { //check if uploaded file is right type if ($fields['wpcf-intern-cv']['field_data']['type'] != 'application/pdf') { //set error message for file $errors['intern-cv'] = 'Wrong file type'; } } //return result return array($fields,$errors); } add_filter('cred_form_ajax_upload_validate','my_validation',10,2);
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cfauv
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.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 3 replies, has 3 voices.
Last updated by 7 years, 5 months ago.
Assisted by: Christian Cox.