2

I'm using a repeating fieldset module (Flexifield, somewhat similar to CCK3 Multigroup) to create a measurement sheet content type. In this, the user is allowed to create an unlimited number of rooms, each defined by five fields: name, level, width, length, area.

It would be really useful to pre-populate about ten of these rows (e.g. "Kitchen," "Bathroom," "Living Room").

How would one go about programmatically creating and filling CCK fields with number of values set to "Unlimited"?

1
  • Sigh... Yet another bounty fail...
    – aendra
    Sep 16, 2011 at 18:36

2 Answers 2

1

Use the Prepopulate module.

5
  • I've seen that before; does that work with fields supplied by a AHAH request?
    – aendra
    Sep 6, 2011 at 17:38
  • Just tried using it, Prepopulate does not generate new rows when the "Add another" button is clicked for infinitely valued Flexifield fields; as such, Prepopulate.module is useless to me.
    – aendra
    Sep 10, 2011 at 6:01
  • Have you tried using hook_form_alter to set the values?
    – user2014
    Sep 10, 2011 at 6:15
  • @Landing -- I've tried a few different ways to no avail; if the input has the name field_levels[0][value][field_level_label][0][value], would the $form variable be: $form['field_levels'][0]['value']['field_level_label'][0]['value']?
    – aendra
    Sep 10, 2011 at 6:47
  • See my answer below.
    – user2014
    Sep 11, 2011 at 21:59
1

In your custom module's form alter function, you can use this code to alter a multivalue field. I use the form inspect module so I can find the form structure of each field. I haven't tested this as a flexifield, but I think it will still work.

$form['field_name']['0']['#default_value']['value'] =t('hello');

$form['field_name']['1']['#default_value']['value'] =t('world');
2
  • Useful! I'll give that a shot later tonight.
    – aendra
    Sep 15, 2011 at 19:05
  • Form Inspect doesn't give any options for the fields within the flexifield type...
    – aendra
    Sep 16, 2011 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.