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"?

  • Sigh... Yet another bounty fail... – aendrew Sep 16 '11 at 18:36
1

Use the Prepopulate module.

  • I've seen that before; does that work with fields supplied by a AHAH request? – aendrew Sep 6 '11 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. – aendrew Sep 10 '11 at 6:01
  • Have you tried using hook_form_alter to set the values? – user2014 Sep 10 '11 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']? – aendrew Sep 10 '11 at 6:47
  • See my answer below. – user2014 Sep 11 '11 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');
  • Useful! I'll give that a shot later tonight. – aendrew Sep 15 '11 at 19:05
  • Form Inspect doesn't give any options for the fields within the flexifield type... – aendrew Sep 16 '11 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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