Quantcast
Channel: Toolset » All Posts
Viewing all articles
Browse latest Browse all 20145

Reply To: [Assigned] CRED Form > Image Dimension Validations

$
0
0

Dear Ryan,

About the file data, there are three parameters which you could use "size, name, error and tmp_name". So look an example of size validation below:

add_filter(‘cred_form_validate’,’my_validation’,10,2);
function my_validation($field_data, $form_data)
{
// field data are field values and errors 
list($fields,$errors)=$field_data;
 
// print the field values 
print_r($fields);
 
// validate if specific form 
if ($form_data[‘id’]==12)
 
if ($fields[‘my_field’][‘value’]['file_data']['my_file']['size'] > ’value’)
 
// set error message per field 
$errors[‘my_field’]=’Wrong Value’;

// return result 
return array($fields,$errors);
}

Look the piece of the article which contains this explanation:

FILE / IMAGE FIELDS
for field types like file or image, the field values of the $fields array
contain also the upload data (if an upload was performed)
eg for a field of type file with name ‘my_file’

$fields[‘my_file’][‘value’]=array(
'value'=>the url of the file (not final one if upload is currently done, or the actual file url if upload was done previously),
'file_data'=>array(‘my_file’=>
 
‘size’=> uploaded file size,
 
‘name’=> name of uploaded file,
 
‘error’=> what error occurred during upload,
 
‘tmp_name’=> location of temporary uploaded file
 
), // only set if actual upload is performed, else empty
'file_upload'=>empty array/not used
);
 
);

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.


Viewing all articles
Browse latest Browse all 20145

Trending Articles