Tell us what you are trying to do?
im trying to restrict the type of file upload in cred forms but it doesnt.
The field form should allow only pdf and docx documents.
Right now im using the hook cred_save_data.
The weard thing is i've created for a client the same form and i tried it before and that one works just fine.
What is the link to your site?
right now im in a local environment.
Here the file field in the form:
<div class="form-group">
<label for="%%FORM_ID%%_documento-obra-escritor">[cred_i18n name='documento-obra-escritor-label']
Documento obra escritor (PDF, DOCX)[/cred_i18n]</label>
[cred_field field='documento-obra-escritor' force_type='field' class='form-control' output='bootstrap']
</div>
Here is the functions involved:
function wrc_get_form_ids() {
$create_user = get_option('create_user_wrc');
$update_user = get_option('update_user_wrc');
$delete_user = get_option('delete_user_wrc');
$create_literary_work = get_option('create_literary_work_wrc');
$update_literary_work = get_option('update_literary_work_wrc');
$create_moderate_work = get_option('moderate_literary_work_wrc');
$form_ids = array(
'create_user_wrc' => $create_user,
'update_user_wrc' => $update_user,
'delete_user_wrc' => $delete_user,
'create_literary_work_wrc' => $create_literary_work,
'update_literary_work_wrc' => $update_literary_work,
'moderate_literary_work_wrc'=> isset($moderate_literary_work) ? $moderate_literary_work : null
);
return $form_ids;
}
function cred_filetype_size_validation($field_data, $form_data){
$form_ids = wrc_get_form_ids();
// Field data are field values and errors
list($fields,$errors)=$field_data;
$allow_types = array(
'pdf' => 'application/pdf',
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
);
if (( $form_ids['update_literary_work_wrc'] == $form_data['id']) && !empty($_FILES['wpcf-documento-obra-escritor']['name'])) {
//Retrieve file type and size
$file_type_uploaded = $_FILES['wpcf-documento-obra-escritor']['type'];
$file_size_uploaded = $_FILES['wpcf-documento-obra-escritor']['size'];
if ( !in_array($file_type_uploaded, $allow_types) || $file_size_uploaded > 100000 ) {
$errors['documento-obra-escritor'] = 'Lo sentimos, solo se aceptan archivos DOCX ó PDF y no deben exceder los 100KB.';
}
}
if (( $form_ids['create_literary_work_wrc'] == $form_data['id']) && (isset($_FILES['wpcf-documento-obra-escritor']['type'])) && (isset($_FILES['wpcf-documento-obra-escritor']['size']))) {
//Retrieve file type
$file_type_uploaded=$_FILES['wpcf-documento-obra-escritor']['type'];
if ( !in_array($file_type_uploaded,$allow_types) ) {
$errors['documento-obra-escritor']='Lo sentimos, solo se aceptan archivos DOCX ó PDF:';
}
}
if (( $form_ids['moderate_literary_work_wrc'] == $form_data['id']) && (isset($_FILES['wpcf-documento-obra-escritor']['type'])) && (isset($_FILES['wpcf-documento-obra-escritor']['size']))) {
$file_type_uploaded=$_FILES['wpcf-documento-obra-escritor']['type'];
if ( !in_array($file_type_uploaded,$allow_types) ) {
$errors['documento-obra-escritor']='Lo sentimos, solo se aceptan archivos DOCX ó PDF:';
}
}
return array($fields,$errors);
}
add_filter('cred_save_data','cred_filetype_size_validation',10,2);
PD: i realized this problem because now i'm creating a form where only you could upload mp4 video and i'm having the same problem.
Thanks in advance.