GF_Fields::create with Consent field [RESOLVED]

I have a programatically created a consent field, which is marked as required (‘isRequired’ => true). Even though the consent field is checked when submitting the form, the forms is returning an error that the consent field is unchecked.

I believe I’m missing a parameter in the GF_Fields::create, because my other text fields, that were created the same way, work correctly. Does anyone know, what parameters are required for the consent field? Below I’m attaching the code I’m using to create this field. I’m using the gform_form_post_get_meta to create the field.

The field is created correctly, the validation does not work.

$nazev_test = GF_Fields::create( array(
			'type'   => 'consent',
			'id'     => 1520, // The Field ID must be unique on the form
			'formId' => $form['id'],
			'isRequired' => true,
			'label'  => 'TEST label',
			'checkboxLabel' => 'TEST TEXT',
			'description' => ' / lorem ipsum',
			'pageNumber'  => 1, // Ensure this is correct
		) );

		$form['fields'][] = $nazev_test;	
	return $form;

The inputs property is missing, it should be an array containing the configuration of the fields 3 inputs.

If you enable logging via the Forms > Settings page and then add a consent field to a form in the form editor, save the form, and then view the core log you’ll find the log includes the field configuration which you can then use when writing your code.

2 Likes

Thank you very much! I haven’t realized I can use the log to see this data :slight_smile: