Redirect to Continue Multi Step Form

I am building a form that can either begin on the home page or at the ‘/apply’ url. I used this tutorial to build the multi-step form. The form works great if I start from ‘/apply’ and begin at the very beginning of the form process. The form does not work if I start from the home page and get redirected to the second step of the form, then try to submit that second step. This is the error message I receive when I try to submit that second page of the form when I started on the home page:

PHP Fatal error:  Cannot create references to/from string offsets nor overloaded objects in /Applications/MAMP/htdocs/drupal/includes/common.inc on line 6548 PHP Stack trace: PHP   1. {main}() /Applications/MAMP/htdocs/drupal/index.php:0 PHP   2. menu_execute_active_handler() /Applications/MAMP/htdocs/drupal/index.php:21 PHP   3. call_user_func_array() /Applications/MAMP/htdocs/drupal/includes/menu.inc:517 PHP   4. drupal_get_form() /Applications/MAMP/htdocs/drupal/includes/menu.inc:517 PHP   5. drupal_build_form() /Applications/MAMP/htdocs/drupal/includes/form.inc:131 PHP   6. drupal_process_form() /Applications/MAMP/htdocs/drupal/includes/form.inc:374 PHP   7. form_builder() /Applications/MAMP/htdocs/drupal/includes/form.inc:842 PHP   8. form_builder() /Applications/MAMP/htdocs/drupal/includes/form.inc:1857 PHP   9. form_builder() /Applications/MAMP/htdocs/drupal/includes/form.inc:1857 PHP  10. form_builder() /Applications/MAMP/htdocs/drupal/includes/form.inc:1857 PHP  11. _form_builder_handle_input_element() /Applications/MAMP/htdocs/drupal/includes/form.inc:1795 PHP  12. drupal_array_set_nested_value() /Applications/MAMP/htdocs/drupal/includes/form.inc:2003 

I am attempting to continue the multi-step form from the home page to the ‘/apply’ page by saving the $form_state['storage'] array in the session, then reading it out of the session in the custom_module_primary_form function.

//Save form 'storage' in $_SESSION function custom_module_first_form_submit($form, &$form_state) {   ...   if(request_path() == '') {     $form_state['redirect'] = array('apply');     $_SESSION['storage'] = $form_state['storage'];     $form_state['rebuild'] = FALSE;   } } 

This is the modified custom_module_primary_form function from the tutorial.

//Read form 'storage' out of $_SESSION function custom_module_primary_form($form, &$form_state) {   // Check to see if anything has been stored.   if ($form_state['rebuild']) {     $form_state['input'] = array();   }    if (empty($form_state['storage'])) {     if(isset($_SESSION['storage'])) {       $form_state['submitted'] = TRUE;       $form_state['rebuild'] = TRUE;       $form_state['storage'] = $_SESSION['storage'];        unset($_SESSION['storage']);     } else {       // No step has been set so start with the first.       $form_state['storage'] = array(         'step' => 'custom_module_first_form',       );     }   }    // Return the current form   $function = $form_state['storage']['step'];   $form = $function($form, $form_state);   return $form; } 
This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

Redirect to Continue Multi Step Form

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.