Notice: Undefined index: type i _webform_client_form_submit_flatten() (rad 3378 av sites/all/modules/contrib/webform/webform.module).
Notice: Undefined index: type i _webform_client_form_submit_flatten() (rad 3378 av sites/all/modules/contrib/webform/webform.module).
Notice: Undefined index: type i _webform_client_form_submit_process() (rad 3362 av sites/all/modules/contrib/webform/webform.module).
Notice: Undefined index: i webform_component_include() (rad 4605 av sites/all/modules/contrib/webform/webform.module).
Notice: Undefined index: type i webform_submission_data() (rad 26 av sites/all/modules/contrib/webform/includes/webform.submissions.inc).
Notice: Undefined index: type i webform_webform_submission_presave() (rad 1245 av sites/all/modules/contrib/webform/webform.module).

This issue https://www.drupal.org/node/1720034 seems to address my problem, but ends with "Closing as this looks like a damaged / modified webform. I'm not a fan of adding lots of defensive programming against damaged data structures that should never be damaged. It leads to unbounded code bloat." by DanChadwick. How do I find out the correct formatting of adding fields to a webform?

I need to add fields which are only used to perform actions in webform_submission_insert. That is I need them in the $submission variable of that function. I've managed to get everything working apart from the error messages above. As soon as I add 'type' as per first line of the error notice I loose the data from $submission.

<?php
function webform_createaccount_form_webform_client_form_alter(&$form, &$form_state, $form_id) {
	$nid = $form['#node']->vid;
	$num_fields = count($form['submitted']);
	$num_components = count($form['#node']->webform['components']);
	
	$num_fields++;
	$wca_field_one = array(
		'#title' => t('Name'),
		'#type' => 'textfield',
		'#description' => t('<i>Type your e-mail address here to register and receive a confirmation e-mail.</i>'),
		'#weight' => ($num_fields + 1),
		'#webform_component' => array(
			'nid' => $form['#node']->vid,
			'cid' => ($num_components+2),
			'pid' => 0,
			'type' => 'textfield',
			'form_key' => 'user_registration_name',
			'name' => t('User Registration Name'),
			'required' => 1,
			'weight' => 10,
			'page_num' => 1,
		),
	);
	$num_fields++;
	$wca_field_two = array(
		'#title' => t('Password'),
		'#type' => 'textfield',
		'#description' => t('<i>Type your e-mail address here to register and receive a confirmation e-mail.</i>'),
		'#weight' => ($num_fields + 1),
		'#webform_component' => array(
			'nid' => $form['#node']->vid,
			'cid' => ($num_components+3),
			'pid' => 0,
			'type' => 'textfield',
			'form_key' => 'user_registration_password',
			'name' => t('User Registration Password'),
			'required' => 1,
			'weight' => 11,
			'page_num' => 1,
		),
	);
	$num_fields++;
	$wca_field_three = array(
		'#title' => t('Your e-mail'),
		'#type' => 'textfield',
		'#description' => t('<i>Type your e-mail address here to register and receive a confirmation e-mail.</i>'),
		'#weight' => ($num_fields + 1),
		'#webform_component' => array(
			'nid' => $form['#node']->vid,
			'cid' => ($num_components+4),
			'pid' => 0,
			'type' => 'textfield',
			'form_key' => 'user_registration_email',
			'name' => t('User Registration E-mail'),
			'required' => 1,
			'weight' => 12,
			'page_num' => 1,
		),
	);
	$num_fields++;
	$wca_fieldset = array(
    '#title' => t('Log in or register to complete this form'), 
    '#type' => 'fieldset',
    '#description' => t('Not signed in? You need to <a href="/user">log in</a> or register to submit this form.'),
    '#weight' => $num_fields, 
    '#collapsible' => TRUE, 
    '#collapsed' => FALSE,
    '#webform_component' => array (
    	/* 'type' => 'fieldset', */
    	'nid' => $form['#node']->vid,
			'cid' => ($num_components+1),
			'pid' => 0,
			'form_key' => 'login_or_register',
			'name' => t('Login or register'),
			'required' => 1,
			'weight' => 10,
			'page_num' => 1,
			'children' => array(
				$wca_field_one['#webform_component'],
				$wca_field_two['#webform_component'],
				$wca_field_three['#webform_component'],
			), 
    ),
   );

	$wca_fields = $wca_fieldset;
	$wca_fields['user_name'] = $wca_field_one;
	$wca_fields['user_password'] = $wca_field_two;
	$wca_fields['user_email'] = $wca_field_three;

	$form['submitted']['login_or_register'] = $wca_fields;

	$form_state['webform']['component_tree']['children'][] = $wca_fieldset['#webform_component'];
	//$form_state['webform']['component_tree']['children'][] = $wca_field_one;
	//$form_state['webform']['component_tree']['children'][] = $wca_field_two;
	//$form_state['webform']['component_tree']['children'][] = $wca_field_three;
	
	$form['#node']->webform['components'][] = $wca_fieldset['#webform_component'];
	$form['#node']->webform['components'][] = $wca_field_one['#webform_component'];
	$form['#node']->webform['components'][] = $wca_field_two['#webform_component'];
	$form['#node']->webform['components'][] = $wca_field_three['#webform_component'];

}

I'm really stuck on trying to understand the correct structure. I would dearly love to surpress the error notices, because from a pragmatic stand point the code does what it should, need to do: It creates the temporary extra fields and brings the data over to webform_submission_insert $submission-variable.

Comments

leanderl created an issue. See original summary.

leanderl’s picture

Issue summary: View changes
DanChadwick’s picture

Category: Task » Support request
Status: Active » Fixed

Components should be defined and added to the form via the UI, not programmatically. The data structures will change from time-to-time as webform features are added.

You should define a new component type, if needed, for the password.

I recommend you always use the latest version, currently 4.11.

And, as the big STOP notice say, we don't supply custom coding support in the issue queue. Try the forum, IRC, or Drupal Answers.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.