Is possible add file upload in the block configure page.

It looks that it can not work.

Cheers

Comments

phpdiva’s picture

Maybe not. But I think you could work around that with some sort of AHAH trickery or popup that performs the upload and inserts the file name into your form field? I would examine the core Upload module to see how it's done.

jyoti_hosetti’s picture

hi,

yes , its possible to add file upload in block configration module.

But for this you need to know some basics of coding.

Steps

1- Enable the block module for file upload. i.e. add the multipart/form-data attribute in form in configure page
For this add line

 $form['#attributes'] = array('enctype' => 'multipart/form-data');

in block_admin_configure in block.admin.inc in block module.(You will find it in site/Module/block)

2-now just add file upload button in block configure page and go. :)
open your block module and search for the line

else if ($op == 'configure' && $delta == 0) {
in function your_module_name_block
and add $form['file_upload'] = array(
    		'#type' => 'file',
    		'#title' => 'Filename'
  		);

      return form;

(check this line is already present or not)
3-for saving the file check the line

}else if ($op == 'save'

in same function in your block and add file upload code there

:)

mikemiles86’s picture

You don't need to alter core. You can alter the form using the hook_form_alter() in your module, like so:

<yourmodulename>_form_alter(&$form, $form_state, $form_id){
	if($form_id == 'block_admin_configure'){
		$form['#attributes'] = array('enctype' => "multipart/form-data");
	}
}

- Michael Miles

gaëlg’s picture

Nice ! I could not figure out why it didn't work. The form built in case 'configure': can't be given special properties like #attributes. Those properties need to be added with form_alter, as mikemiles86 mentioned. Then it works like a charm. Thanks !

doostinharrell’s picture

Four Kitchens has a tutorial that explains this very well.  I used it this morning. 

https://www.fourkitchens.com/blog/article/building-custom-blocks-drupal-7/