Can I get some help with a multi step form I am creating. Sorry about the long form.

I currently get an ajax error after clicking Next Step.

An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
Path: /system/ajax
StatusText: Service unavailable (with message)
ResponseText: PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'experience' in 'field list': INSERT INTO {custom_application} (name, lastname, email, zip, address, phone, cell, gender, birthday, schedule, friend, name_emerg, address_emerg, phone_emerg, relation_emerg, experience, physcond, allergens, questions, created) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11, :db_insert_placeholder_12, :db_insert_placeholder_13, :db_insert_placeholder_14, :db_insert_placeholder_15, :db_insert_placeholder_16, :db_insert_placeholder_17, :db_insert_placeholder_18, :db_insert_placeholder_19); Array
(
[:db_insert_placeholder_0] => admin
[:db_insert_placeholder_1] => qasdf
[:db_insert_placeholder_2] => asdfa
[:db_insert_placeholder_3] => asdfasdf
[:db_insert_placeholder_4] =>
[:db_insert_placeholder_5] =>
[:db_insert_placeholder_6] => asdf
[:db_insert_placeholder_7] => 1
[:db_insert_placeholder_8] => asdf
[:db_insert_placeholder_9] => 0
[:db_insert_placeholder_10] =>
[:db_insert_placeholder_11] => asdf
[:db_insert_placeholder_12] => sadf
[:db_insert_placeholder_13] => asdf
[:db_insert_placeholder_14] => asdf
[:db_insert_placeholder_15] =>
[:db_insert_placeholder_16] =>
[:db_insert_placeholder_17] =>
[:db_insert_placeholder_18] =>
[:db_insert_placeholder_19] => 1311052044
)
in application_nameform_submit() (line 351 of /Users/JosephPGarrido/Sites/YoginiAsako/sites/all/modules/custom/application/application.module).

<?php
// print_r($vars);
/**
 * FORM API
 */

/*
 * Implements hook_menu()
 */
function application_menu() {
	$items['application'] = array(
		'title' => 'Application',
		'page callback' => 'drupal_get_form',
		'page arguments' => array('application_nameform'),
		'access callback' => TRUE,
		'type' => MENU_NORMAL_ITEM
	);
	return $items;
}
/*
 * Implements hook_theme
 */
function application_theme() {
	return array(
	'application_nameform' => array(
		'render element' => 'form',
		'template' => 'application_nameform',
		),
	);
}

/*
 * Assign the elements of the form to variables
 */
function template_preprocess_application_nameform(&$variables) {
	$variables['application_nameform'] = array();
	$hidden = array();
	//Provides variables named after form keys
	foreach (element_children($variables['form']) as $key) {
		$type = $variables['form'][$key]['#type'];
		if ($type == 'hidden' || $type == 'token') {
			$hidden[] = drupal_render($variables['form'][$key]);
		}
		else {
			$variables['application_nameform'][$key] = drupal_render($variables['form'][$key]);
		}
	}
	// Hidden form elements have no value to the theme
	$variables['application_nameform']['hidden'] = implode($hidden);
	// Collect all form elements
	$variables['application_name_form'] = implode($variables['application_nameform']);
}
/*
 * Define the form fields
 */
function application_nameform($form, &$form_state) {
	$form['#prefix'] = '<div id="wizard-form-wrapper">';
  $form['#suffix'] = '</div>';
  $form['#tree'] = TRUE; // We want to deal with hierarchical form values.
// Assign form ID
	$form['#id'] = 'appForm';
	$form['#contact'] = $contact;
	$form_state['contact'] = $contact;
	
  // $form_state['storage'] has no specific drupal meaning, but it is
  // traditional to keep variables for multistep forms there.
  $step = empty($form_state['storage']['step']) ? 1 : $form_state['storage']['step'];
  $form_state['storage']['step'] = $step;

  // Fields
  switch ($step) {
    case 1:
			$form['name'] = array(
				//First name
				'#title' => t('First'),
				'#type' => 'textfield',
				'#description' => t(''),
				'#required' => TRUE
			);
			$form['last_name'] = array(
				//Last name
				'#title' => t('Last'),
				'#type' => 'textfield',
				'#description' => t(''),
				'#required' => TRUE
			);
			$form['email'] = array(
				//Last name
				'#title' => t('Email'),
				'#type' => 'textfield',
				'#description' => t(''),
				'#required' => TRUE
			);
			//Adress Info
			$form['zip'] = array(
				//Zip
				'#title' => t('Zip'),
				'#type' => 'textfield',
				'#description' => t(''),
				'#required' => TRUE
			);
			$form['address'] = array(
				//phys address
				'#title' => t('Phys Address'),
				'#type' => 'textarea',
				'#maxlength' => 500, 
				'#description' => t(''),
			);
			//Phone Numbers
			$form['home_phone'] = array(
				//phone
				'#title' => t('Home Phone'),
				'#type' => 'textfield',
				'#description' => t(''),
			);
			$form['cell_phone'] = array(
				//phone
				'#title' => t('Cell phone'),
				'#type' => 'textfield',
				'#description' => t(''),
				'#required' => TRUE
			);
			$form['gender'] = array(
				//Gender
				'#title' => t('Gender'),
				'#type' => 'radios',
				'#options' => array(t('female'), t('male')),
				'#description' => t(''),
			);
			$form['birthday'] = array(
				//Birth
				'#title' => t('Birthday'),
				'#type' => 'textfield',
				'#description' => t(''),
				'#required' => TRUE
			);
			$form['schedule'] = array(
				//schedule selection
				'#title' => t('Schedule'),
				'#type' => 'select',
				'#options' => array(t('1'), t('2')),
				'#description' => t(''),
				'#required' => TRUE
			);
			$form['friend'] = array(
				//friend
				'#title' => t('Friends Name'),
				'#type' => 'textfield',
				'#description' => t('Bringing a friend or relative?'),
			);
			
			// Emergency Contact
			$form['name_emerg'] = array(
				//First name
				'#title' => t('Name'),
				'#type' => 'textfield',
				'#description' => t(''),
				'#required' => TRUE
			);
			$form['address_emerg'] = array(
				//address
				'#title' => t('Address'),
				'#type' => 'textarea',
				'#description' => t(''),
				'#required' => TRUE
			);
			$form['phone_emerg'] = array(
				//phone
				'#title' => t('Phone'),
				'#type' => 'textfield',
				'#description' => t(''),
				'#required' => TRUE
			);
			$form['relation_emerg'] = array(
				//relationship
				'#title' => t('Relationship'),
				'#type' => 'textfield',
				'#description' => t(''),
				'#required' => TRUE
			);
			
		break;
		
		case 2:	
			$form['experience'] = array(
				//experience
				'#title' => t('Experience'),
				'#type' => 'textarea',
				'#description' => t(''),
			);
			$form['physcond'] = array(
				//Phys Cond
				'#title' => t('Physical conditions'),
				'#type' => 'textarea',
				'#description' => t(''),
			);
			$form['allergens'] = array(
				//Allergens
				'#title' => t('Allergens'),
				'#type' => 'textarea',
				'#description' => t(''),
			);
	break;
	
	case 3:
			$form['questions'] = array(
				//questions
				'#title' => t('Qestions'),
				'#type' => 'textarea',
				'#description' => t(''),
			);
	break;
  }
  
  if ($step == 3) {
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t("Submit your information"),
    );
  }
  
  if ($step < 3) {
    $form['next'] = array(
      '#type' => 'submit',
      '#value' => t('Next step'),
      '#ajax' => array(
        'wrapper' => 'wizard-form-wrapper',
        'callback' => 'application_nameform_ajax_callback',
      ),
    );
  }
  if ($step > 1) {
    $form['prev'] = array(
      '#type' => 'submit',
      '#value' => t("Previous step"),

      // Since all info will be discarded, don't validate on 'prev'.
      '#limit_validation_errors' => array(),
      // #submit is required to use #limit_validation_errors
      '#submit' => array('application_nameform_ajax_callback'),
      '#ajax' => array(
        'wrapper' => 'wizard-form-wrapper',
        'callback' => 'application_nameform_ajax_callback',
      ),
    );
  }

	return $form;
}
/*
 * Ajax callback
 */
function application_nameform_ajax_callback($form, &$form_state) {
//  $element = $form['box'];
 
//  return $element; 
	return $form;
}

/*
 * Form submit function and email
 */
function application_nameform_submit($form, &$form_state) {
	// Save away the current information.
  $current_step = 'step' . $form_state['storage']['step'];
  if (!empty($form_state['values'][$current_step])) {
    $form_state['storage']['values'][$current_step] = $form_state['values'][$current_step];
  }

  // Increment or decrement the step as needed. Recover values if they exist.
  if ($form_state['triggering_element']['#value'] == t('Next step')) {
    $form_state['storage']['step']++;
    // If values have already been entered for this step, recover them from
    // $form_state['storage'] to pre-populate them.
    $step_name = 'step' . $form_state['storage']['step'];
    if (!empty($form_state['storage']['values'][$step_name])) {
      $form_state['values'][$step_name] = $form_state['storage']['values'][$step_name];
    }
  }
  if ($form_state['triggering_element']['#value'] == t('Previous step')) {
    $form_state['storage']['step']--;
    // Recover our values from $form_state['storage'] to pre-populate them.
    $step_name = 'step' . $form_state['storage']['step'];
    $form_state['values'][$step_name] = $form_state['storage']['values'][$step_name];
  }

  // If they're done, submit.
  if ($form_state['triggering_element']['#value'] == t('Submit your information')) {
    $value_message = t('Your information has been submitted:') . ' ';
    foreach ($form_state['storage']['values'] as $step => $values) {
      $value_message .= "$step: ";
      foreach ($values as $key => $value) {
       $value_message .= "$key=$value, ";
      }
    }
    drupal_set_message($value_message);
    $form_state['rebuild'] = FALSE;
    return;
  }

  // Otherwise, we still have work to do.
  $form_state['rebuild'] = TRUE;
	
	// POST Info
	$name = $form_state['values']['name'];
	$lastname = $form_state['values']['last_name'];
	$email = $form_state['values']['email'];
	$zip = $form_state['values']['zip'];
	$address = $form_state['values']['address'];
	$phone = $form_state['values']['home_phone'];
	$cellphone = $form_state['values']['cell_phone'];
	$gender = $form_state['values']['gender'];
	$birthday = $form_state['values']['birthday'];
	$schedule = $form_state['values']['schedule'];
	$friend = $form_state['values']['friend'];
	$name_emerg = $form_state['values']['name_emerg'];
	$address_emerg = $form_state['values']['address_emerg'];
	$phone_emerg = $form_state['values']['phone_emerg'];
	$relation_emerg = $form_state['values']['relation_emerg'];
	$experience = $form_state['values']['experience'];
	$physcond = $form_state['values']['physcond'];
	$allergens = $form_state['values']['allergens'];
	$questions = $form_state['values']['questions'];
	
	$params['form'] = $form_state;
	
// New db_insert
db_insert('custom_application')
		->fields(array(
			'name' => $name,
			'lastname' => $lastname,
			'email' => $email,
			'zip' => $zip,
			'address' => $address,
			'phone' => $phone,
			'cell' => $cellphone,
			'gender' => $gender,
			'birthday' => $birthday,
			'schedule' => $schedule,
			'friend' => $friend,
			'name_emerg' => $name_emerg,
			'address_emerg' => $address_emerg,
			'phone_emerg' => $phone_emerg,
			'relation_emerg' => $relation_emerg,
			'experience' => $experience,
			'physcond'	=> $physcond,
			'allergens' => $allergens,
			'questions' => $questions,
			'created' => REQUEST_TIME,
	))
->execute();

	// Send email to admin
		$admin ="foo@foo.com";
//	$admin = "foo@foo.com";
		$from = "noreply@foo.com";
	// Submitted email form value
		$notifiyVisitor = $email;
	
  // Send Email to admin
	$result = drupal_mail('contact', 'notify', $admin, language_default(), $params, $from, $send = TRUE);
  // Send Email to visitor
  $result = drupal_mail('contact', 'notifyVisitor', $notifiyVisitor, language_default(), $params, $from, $send = TRUE);
  
  
  if ($result['result'] == TRUE) {
    drupal_set_message(t('Your message has been sent.'));
  }
}

/* Admin and Visitor notify
 * hook_mail().
 */
function application_mail($key, &$message, $params) {
	switch ($key) {
		case 'notify':
			$message['subject'] = t('Asakos Website Contact Form - '. $params['form']['values']['name']);
			$message['body'][] = t('New information has been recorded. Contact information is below:')."\n".
			t('Name: '. $params['form']['values']['name']) ."\n".
			t('E-mail: '. $params['form']['values']['email']) ."\n".
			t('Comments: '. $params['form']['values']['comments']) ."\n".
			
			// Escape unintentional html inside of body
			$message['body'][] = check_plain($params['message']);
			break;
	}
	switch ($key) {
		case 'notifyVisitor':
			$message['subject'] = t('Thank you - '. $params['form']['values']['name']);
			$message['body'][] = t('The information you submitted to us is below:')."\n".
			t('Name: '. $params['form']['values']['name']) ."\n".
			t('E-mail: '. $params['form']['values']['email']) ."\n".
			t('Comments: '. $params['form']['values']['comments']) ."\n".
			
			t('Thank you again and we will get back to you shortly about your question') ."\n".
			t('www.YoginiAsako.com') ."\n".
			// Escape unintentional html inside of body
			$message['body'][] = check_plain($params['message']);
			break;
	}
}

Comments

Anonymous’s picture

It's a bog-standard SQL error message: "Unknown column 'experience' in 'field list'" means that you're trying to insert data into a table which does not have a column named 'experience'. Just check the code you're using to insert the record against the columns that actually exist in the database and you'll be fine

arkjoseph’s picture

Thanks, but I am still getting no success with the error. I double checked the table and I continue to get the error "Integrity constraint violation: 1048 Column 'name' cannot be null:"

The table looks like the following:

cid 	int(11) 			No 		auto_increment
lastname 	varchar(50) 	utf8_general_ci 		
email 	varchar(100) 	utf8_general_ci 		
zip 	        varchar(50) 	utf8_general_ci 		 	
address 	varchar(300) 	utf8_general_ci 		
phone 	varchar(20) 	utf8_general_ci 		
cell 	        varchar(20) 	utf8_general_ci 	
gender 	varchar(10) 	utf8_general_ci 	
birthday 	varchar(20) 	utf8_general_ci 		
schedule 	varchar(50) 	utf8_general_ci 	
.....and the rest

I think my insert query has something to do with the error, because if I comment it out, i can move through the form.

// New db_insert
db_insert('custom_application')
->fields(array(
'name' => $name,
'lastname' => $lastname,
'email' => $email,
'zip' => $zip,
'address' => $address,
'phone' => $phone,
'cell' => $cellphone,
'gender' => $gender,
'birthday' => $birthday,
'schedule' => $schedule,
'friend' => $friend,
'name_emerg' => $name_emerg,
'address_emerg' => $address_emerg,
'phone_emerg' => $phone_emerg,
'relation_emerg' => $relation_emerg,
'experience' => $experience,
'physcond' => $physcond,
'allergens' => $allergens,
'questions' => $questions,
'created' => REQUEST_TIME,
))
->execute();

Do I need to implement "Multi-insert form" from http://drupal.org/node/310079 ?