Download & Extend

Filefield not working when modified with hook_form_alter

Project:FileField
Version:6.x-3.1
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed (won't fix)
Issue tags:ahah, form_alter, hook_form_alter

Issue Summary

Hi,

I'm using hook_form_alter to alter a fieldfield and move into a wrapper #type => 'markup' form element. This wrapper is used to hide the filefield and other fields with haha when some value are selected in a taxonomy field.

It works when I'm not using ahah submission of the filefield, but not when using haha (when pushing the Upload). I looked up in filefield.module:filefield_js() i found out that

  1. hook_form_alter implementations are not invoked. I'm still new to Drupal, filefield and ahah but, according to Doing AHAH Correctly in Drupal 6, drupal_process_form() and drupal_rebuild_form should be invoked, where filefield only call form_builder.
  2. The filefield form element is fetched from the form using an un-alterable form path taking only fieldgroup and multigroups into accounts.

I can probably work around the second point by detecting that the MY_form_alter invocation is done in the context of the filefield ahah (arg(0) == 'fielfield' && arg(1) == 'ahah') and move the field back to its expected form path. But since the hook is not called, it couldn't not be done.

I'll probably try to patch filefield_js() myself, but maybe there is good reason to not call drupal_process_form() and drupal_rebuild_form like recommended.

Comments

#1

(add tags)

#2

Status:active» needs review

Borrowing code from ahah_helper module, I came with the following patch which seems to work...

AttachmentSize
filefield_ahah_hook_alter.patch 2.08 KB

#3

I am quite interested in this as well. Any plans to get formal Drupal form processing in there at some point (particularly in the filefield_js function)?

#4

Title:Fielfield not working when modified with hook_form_alter» Filefield not working when modified with hook_form_alter

Updating issue title

#5

Status:needs review» needs work

This approach introduces security problems by disabling #element_validate on elements, even though they are still processed. I'd suggest just using hook_elements() like FileField Sources and ImageField Extended do, which makes it so that you can move your FileFields around in the form (such as in Fieldsets) and not have them break.

#6

Subscribing, I need this functionality too.

#7

It's probably worth mentioning that while the patch in #2 does allow adding new fields to widget elements the elements are lost (at least in my case) if CCKs "Add another item" function is used to load another object.

For example:

  1. Upload a file
    • The widget element replaces the upload element
    • The additional form elements are present
  2. Click "Add another item"
    • A new upload element is added to the form
    • The added form elements from the first widget element disappear.

#8

Category:bug report» feature request
Status:needs work» closed (won't fix)

Per my notes in #5, this request is incorrect and you should use hook_elements() to modify FileField.

nobody click here