4

I'm guessing someone must have done this before but I can't find a module for it.

In Feeds the last file you imported can be seen by name on the left hand side. Next to the 'Browse' box.

If the user doesn't browse for a file then the File shown in that box is imported when clicking on the 'submit' button. What I'd like to do is to leave this file being shown as the last import but I don't want it to be imported if no file has been selected.

Has anyone done this or something similar .

  • Hi Deejay,I'm free now and can help you. do you want prevent(face user with error that you are not browsed file) or nothing happened? – Yusef Jun 21 '16 at 9:16
0
+50

you can simplely remove it by using hook_form_alter

don't forget replace form_id and yourmodulename with yours in following code

function yourmodulename_form_alter(&$form,$form_state,$form_id){
    if($form_id=='feeds_import_form' ){
    unset($form['feeds']["FeedsFileFetcher"]['upload']['#file_info']);
}
}

update in this section we prevent user to resubmit the old file,this mean if user push import button without browsed new file we prevent him to remport

function mymodule_form_alter(&$form,$form_state,$form_id){
    if($form_id=='feeds_import_form' ){
      $form['#validate'][] = 'mymodule_prevent_import_validate';    
}
}

function mymodule_prevent_import_validate($form,$form_state){
    if(!isset($form_state['values']['feeds']["FeedsFileFetcher"]['file'])){
            form_set_error('upload', t('Not new file uploaded'));
            return false;
    }
}
  • Hi Zhilevan Thanks for this . However this get's rid of the File name from view but when clicking on import the file still imports. I kind of want the opposite - I'd like to still be able to see the filename of the last upload but when clicking on Import for it to not import, that should only come from if a file has been browsed for. – Deejay Jun 20 '16 at 12:55
  • @Deejay So you should handle it custom submit handler, add ( array_unshift ) your custom submit(or validator) handler, in custom submit(validate)handler if not data posted do nothing(or return form error to fill it ) . I'am sure the the solution for this is simple. – Yusef Jun 20 '16 at 13:57
  • @Deejay I update my question .take a look at second part – Yusef Jun 21 '16 at 9:44

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.