I need to validate the Image Name uploaded via Image field in Content type.How can i validate the Image name.
Any Help is Appreciated
Thanks,
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityfunction hook_form_alter(&$form, &$form_state, $form_id){
if($form_id == "YOUR_FORM_ID"){
$form['#validate'][] = 'myvalidation_function';
}
}
function myvalidation_function($form, &$form_state) {
$file_fid = $form['field_your_content_type_image_field']['LANGUAGE_NONE'][0]['#value'][fid];
$file = file_load($file_fid);
$file_name = explode( '.', $file->filename);
if($file_name[0] != $form['type']['#value']){
drupal_set_message('your validation error');
}
}
Hope this works. I have tested on my system :)