Trying to use flexinode to upload files to the server, but each time the system returns to the page with the message:

You must fill in the field "File".
("File" is the lable given to the 'file' field)

It seems like it is not recognising that a file was selected. Nothing is added to the database.

CommentFileSizeAuthor
#14 flexinode.patch_3_0.txt1.24 KBBèr Kessels
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

scroogie’s picture

Had the same issue with Images. If i recall correctly the problem was the call to file_save_upload() in flexinode_field_image_insert(), because it was already called in flexinode_field_image_execute(). Try commenting out this line in insert().

gmak’s picture

That doesn't seem to be the case here. "flexinode_field_file_insert()" doesn't have the same call as "flexinode_field_file_execute()". There is only one file_save_upload called (and that is in "flexinode_field_file_execute()".

Any other suggestions?

scroogie’s picture

Does it work if you replace variable_get('file_directory_path', NULL) with file_directory_path()? That seems to be the only difference to field_image.inc

gmak’s picture

If I've followed your suggestion correctly and changed:

variable_get('file_directory_path', NULL)

to

variable_get('file_directory_path()', NULL)

then the answer is no, it still doesn't work.

I can attach files (using the attachment.module) and upload images using img_assist.module and image.module, so I don't think it is an issue with my setup. The problem must be somewhere in flexinode.

Any other ideas?

(By the way, thanks for helping sort this out ... if we can sort it out)

gmak’s picture

I might be getting closer. What I find is that if I uncheck the "Required field" checkbox in the content type setting for the 'File' field, the uploading works. So, the problem is somewhere in the field validation which checks this field.

Can anyone suggest where I might be able to find a way to solve that?

Thanks,

cooperaj’s picture

I have this exact same issue. Will have a look at the validation code but I can't promise that i'll find anything.

In the meantime I'll take out the required selection.

cooperaj’s picture

After a very cursory look it seems that 'field_file.inc' does not have a flexinode_field_file_validate()' function. So when the validate hook is called it does not get to return a correct value. I'm assuming this results in a 'false' return and so prompts the user.

I'll try to implement the function.

cooperaj’s picture

I was wrong. Adding a validate function did nothing.

Doing a print_r($node) on the entrance to flexinode_validate($node) shows that the item it checks is indeed empty. I don't know why it is empty and I'm not sure how the whole validate/execute thing works anyway so I'm going to have to leave this for a short while.

Hopefully this can be resolved.

chud’s picture

Version: » master

I would love to know if anyone has been able to resolve this! I have a project that needs 'required' image fields.

I've tried to debug the code to figure out what's wrong, but I'm pretty much at a loss. As far as I can tell the $node object that is used in flexinode_validate() is incomplete. In my case the image field is known as flexinode_8. $node->flexinode_8 is always NULL. However, normally $node->flexinode_8 contains more information such as $node->flexinode_8->thumbpath for instance.

Any solution that would enable me to have required image fields in my flexinodes would be great!

Here is another post about the same issue: http://drupal.org/node/54061

Thanks!

PS- I'm using 4.7 with Flexinode CVS

samc’s picture

Assigned: Unassigned » samc

Wow, what a way to kill an evening ;-)

To recap: The upload mechanism is working fine. Problem is in validation when the field is required.

Turns out, even if you get past flexinode_validate() in flexinode.module, the form is rejected by the validation routine in core. (_form_validate in form.inc).

Bottom line seems to be that both validation routines are looking for the (required) form field to have a value, and the "file" field type does not return a value.

I tried (albeit, a 1:00 am try) to implement a custom validation routine using #validate in the form, but this doesn't seem to _override_ the validation in core, just offers a place to insert additional checks.

I don't see an easy way around these issues, so looking to more experienced drupal folks to advise.

samc’s picture

Title: file upload doesn't recognise that a file was selected » Required flag on file forms breaks on validation

Bèr posted an issue to core about this issue:

Required flag on file forms breaks on validation
Bèr Kessels - April 21, 2006 - 07:43
Project: Drupal
Version: cvs
Component: file system
Category: bug
Priority: critical
Assigned: Unassigned
Status: active

Description

A file form, that is required will always fail. Since there is no #value set (theoratically, there is no value at all) the validation will start nagging about the field having no value.

We either need a different validation for requirement of files in form api, or we need to set something usefull (like the $file object) as #value, once file.inc validated the file.

Flexinode file fields are one of the cases where this behaviour can be reproduced.

samc’s picture

A value can be 'spoofed' by manually setting it in the form like so:

  $form[$fieldname] = array(
    '#type' => 'file',
    '#title' => t($field->label),
    '#description' => ($node->$fieldname ? t('"%filename" has been uploaded. If you upload another file, the current file will be replaced.', array('%filename' => $node->$fieldname->filename)) : '') . t($field->description),
    '#required' => $field->required,
    '#weight' => $field->weight,
    '#value' => '1',
    );

This will get the field to validate, but I'm not sure it's a supported use of the #value element. Unlike the case in [1], here it's tagging along on a form control of type 'file' (not type 'value'). According to the form api reference[2], this isn't supported.

This is only a partial victory, because if the preview button is used the value in the form field is lost. This isn't related to the approach above, just the fact that the full path isn't available to the server. (This might be client specific, but stuff I've seen[3] suggests that the server shouldn't expect to see the path.)

So, a possible solution is to use some javascript to copy the filepath from the file field to a hidden field on submit, and place that back into the form using the #default_value property when building the form the second time around. Seems resonable, but as of right now, the #default_value property isn't working for controls of type 'file'[4].

I have no idea how to do the javascript stuff in a Drupal-like way, so I'm hoping someone who knows that stuff can chime in.

Was this--namely having the value available after preview--working prior to the 4.7 updates?

Perhaps a look at upload.module is in order?

[1] http://drupal.org/node/54215
[2] http://api.drupal.org/api/HEAD/file/developer/topics/forms_api_reference...
[3] http://www.codecomments.com/archive227-2004-10-305251.html
[4] http://drupal.org/node/60046

samc’s picture

Component: Code » Field types
Priority: Critical » Normal

Per http://drupal.org/node/59750, looks like core developers are tabling this issue until post 4.7 release.

For now, required flag on file fields is not supported.

We can continue to use this thread to post workarounds/patches.

Bèr Kessels’s picture

FileSize
1.24 KB

http://drupal.org/node/60972 was marked duplicate of this issue. It contains a patch too. reattaching that here, for reference.

cooperaj’s picture

Component: Field types » Field type: file

This has been open a looong time. Does the patch still apply? Is flexinode maintained?

I'd like to close this call. I'll leave it a week and come back and close it then.

samc’s picture

Assigned: samc » Unassigned

Can't answer either of those, but I'm no longer actively working this issue so unassigning.

quicksketch’s picture

Status: Active » Closed (fixed)

Flexinode has long been abandoned. This is being fixed in Drupal core in #59750: Required flag on file forms breaks on validation.