Drupal 6.2
Filefield beta2
Apache with Clean URLs on
Firefox 2 with JS enabled

I am able to render a filefield form field using drupal_render('my_file_field');

However, once I click on 'Upload', the entire fieldset disappears.

I've tried to debug, but I need a helpful hint :)

I appreciate your efforts and support, all!

Comments

jpetso’s picture

For JavaScript (AHAH) replacements, Filefield relies on the structure of a node edit form and expects the content_field_form() at $form[$field_name] (or $form[$group_name][$field_name] if the filefield lies inside a fieldgroup). If the filefield form element is somewhere else, an empty result is what you'll get. You might have a look at filefield_js() at the bottom of filefield.widget.inc, that function is very close to CCK's AHAH callback and is the best I could come up with.

If you've got a good idea on how to make it fit into other form structures than the expected one, I'd be interested in seeing your solution :)

raspberryman’s picture

Thanks for that, jpetso. I will do some experimentation to get drupal_render() to play well with filefield.

In the meantime, do you have any ideas on how I could get drupal_render() to work as-is? I appreciate any insights you may offer.

Cheers!

jpetso’s picture

If you place the widget in your form as $form[$field_name], it should probably work. Btw, how do you retrieve the form that you drupal_render() afterwards?

raspberryman’s picture

Hi jpetso,

I theme the node forms considerably, in their own mynodetype-node-form.tpl.php. In them, I execute <?php print drupal_render('myfieldame'); ?> to display the form field. At the bottom, I also render the id, token, and submit button.

The fields I do not want the user to see are set programatically via the formfilter module.

drupal_render() works beautifully for every CCK field type (and for title, body, and taxonomy fields) except filefilter, due to the above issue.

I hope this helps! Thanks again for your insights.

raspberryman’s picture

I was able to get <?php print drupal_render('myfieldame'); ?> to work. I was not rendering form_build_id.

drupal_render() now works great for all cases, except when "Number of Values" is set to Unlimited

In that case, the button "Add another item" adds a new form field, but also empties out all previous fields.

Here is how I am using drupal_render(), in a mynodetype-node-form.tpl.php file:

  print drupal_render($form['title']); 
  print drupal_render($form['myfilefield']); 
  print drupal_render($form['form_token']);
  print drupal_render($form['form_id']);
  print drupal_render($form['form_build_id']);
  print drupal_render($form['buttons']['submit']);

All other form fields (author, options, etc) are being set programatically by formfilter_filter_form() in the Formfilter module.

jpetso’s picture

The "Unlimited" issue was a CCK bug that I fixed already, and the fixes are in the current -rc releases of CCK - please update. I would assume that all of your challenges are resolved now, could you please close this issue as "fixed" if this is the case?

dopry’s picture

Status: Active » Closed (fixed)

and 6.x-1.x is deprecated and I completely rewrite the form interface for the widgets... You might want to test against 6.x-3.x and reopen if you're still having issues.