1

I have an image field defined using CCK. I need to detect or validate that the image has been uploaded. Is it possible?

Thanks to all.

1

You can just set the CCK image field as a required field and the form won't validate unless the user uploads an image.

1

Even easier, you can do it with Rules on condition "Field xx has changed".

1

You may have to use hook_form_FORM_ID_alter().Define your own module and in your module try the following code

function yourModuleName_FORM_ID_alter(&$form, &$form_state) {
  $form['#validate'][] = 'yourModuleName_FORM_ID_validate';
}

//your validation function
function yourModuleName_FORM_ID_validate($form, &$form_state) {
  if (isset($_FILES['files']) && is_uploaded_file($_FILES['files']['tmp_name']['machine_name_of_the_cck_field'])) {
    // File uploaded
  }
  else {
    //File not uploaded
  }    
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.