Repeater data not being saved

Hi all,

Having a problem with nested repeater fields.

It seems if any of the nested fields are left blank, then it doesn’t save the input data for an subsequent nested fields. Here’s an example form to show what I mean. Here are the steps to recreate the problem:

  1. Go to http://owen-lewis.com/gf-repeater-test/
  2. Enter something in the first ‘Element’ field
  3. Leave the first ‘Fact’ and ‘Evidence for Fact’ fields blank
  4. Add a new ‘Element’
  5. Enter some data for all three fields in the new ‘Element’
  6. Submit the form.

You’ll see that the ‘Fact’ and ‘Evidence’ fields for the second ‘Element’ are not saved in the entry.

Here is my code to create the fields:

// Add repeater fields
function add_fields($form){
	$element = GF_Fields::create(array(
		'type'   => 'text',
		'id'     => 1001,
		'formId' => $form['id'],
		'label'  => 'Element',
		'pageNumber'  => 1
	));
	$fact = GF_Fields::create(array(
		'type'   => 'text',
		'id'     => 1003,
		'formId' => $form['id'],
		'label'  => 'Fact',
		'description' => 'List a fact that\'s asserted to support the element.',
		'pageNumber'  => 1
	));
	$evidence = GF_Fields::create(array(
		'type'   => 'text',
		'id'     => 1005,
		'formId' => $form['id'],
		'label'  => 'Evidence for Fact',		
		'description'  => 'What evidence proves or disproves this fact?',
		'pageNumber'  => 1
	));
	$evidences = GF_Fields::create( array(
		'type'             => 'repeater',
		'id'               => 1004, 
		'formId'           => $form['id'],
		'label'            => 'Evidence',
		'addButtonText'    => 'Add evidence', 
		'removeButtonText' => 'Remove evidence', 
		'pageNumber'       => 1,
		'fields'           => array($evidence),
	)); 
	$facts = GF_Fields::create( array(
		'type'             => 'repeater',
		'id'               => 1002, 
		'formId'           => $form['id'],
		'label'            => 'Supporting Facts',
		'addButtonText'    => 'Add fact',
		'removeButtonText' => 'Remove fact',
		'pageNumber'       => 1,
		'fields'           => array($fact, $evidences),
	)); 
	$elements = GF_Fields::create( array(
		'type'             => 'repeater',
		'id'               => 1000, 
		'formId'           => $form['id'],
		'label'            => 'Elements',
		'addButtonText'    => 'Add element',
		'removeButtonText' => 'Remove element',
		'pageNumber'       => 1,
		'fields'           => array($element, $facts),
	)); 
	$form['fields'][] = $elements; 
	return $form;
}
add_filter('gform_form_post_get_meta_1', 'add_fields');

// Remove fields before the form is saved.
function remove_fields($form_meta, $form_id, $meta_name){
	if($meta_name == 'display_meta'){
		// Remove the Repeater field: ID 1000
		$form_meta['fields'] = wp_list_filter($form_meta['fields'], array('id' => 1000), 'NOT');
	} 
	return $form_meta;
}
add_filter('gform_form_update_meta_1', 'remove_fields', 10, 3);

Any Ideas?

Thanks,

Owen.

Hmmm, it seems like the data isn’t serializing properly. Do you have anything going on in an:

If you want to force data to save, you could use gform_after_submission to edit the entry data as needed.

If you keep having issues, why don’t you use a List field and then muck with the CSS to make it look the way you want?

Noticed this same issue. First field of a repeater set will save, other fields will not. No customizations made to the submission process.

© 2008 - 2019. Gravity Forms is a project by Rocketgenius Inc.