Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Fixed Multi-step form "next" incorrect URL - but always staying on 1st step


Reply


675 Views

Avatar
KINKCreative

Community Member, 56 Posts

18 July 2012 at 8:43am

Edited: 21/07/2012 8:17am

FIXED the controller action url by inserting this into the url:

const URLSegment = 'account'; //whatever you use in the Director rule
   
   public function getURLSegment() {
      return self::URLSegment;
   }
   
   public function Link() {
      return self::URLSegment ."/". Controller::getAction();
   }

But now the form always stays on step one. Using ?StepID=1 or any other number returns an error. Help? :)

--- OLD POST ---

I want to use the Multi-Step form as part of a large(ish) registration process.

I setup the multiform as follows:

<?php

class CandidateRegistrationForm extends MultiForm {
   public static $start_step = 'CandidateRegistration_Step1';
}

/* STEPS */

class CandidateRegistration_Step1 extends MultiFormStep {
   protected $title = "Information about your new job";
   public static $next_steps = 'CandidateRegistration_Step2';
   
   function getFields() {
      return new FieldSet(
         ...
      );
   }   
}

class CandidateRegistration_Step2 extends MultiFormStep {
   protected $title = "Experience details";
   public static $next_steps = 'CandidateRegistration_Step3';
...
}

class CandidateRegistration_Step3 extends MultiFormStep {
   protected $title = "Training, languages and executive summary";
   public static $next_steps = 'CandidateRegistration_Step4';
...
}

class CandidateRegistration_Step4 extends MultiFormStep {
   protected $title = "Complete and submit your profile";
   public static $is_final_step = true;
...
}

Since I don't want the page in the SiteTree (I will have multiple sites), so I setup a Director rule in _config.php:

Director::addRules(100, array(
'account' => 'AccountController'
));

The AccountController.php has the various actions I'd like to access, one of which will call the Multi-step form:

class AccountController extends Page_Controller {
   
   public static $allowed_actions = array(
      'index',
      'register',
      'buildprofile',
      'editprofile'
   );
   
   /* ACTIONS */
   
   public function init() {
      parent::init();
   }
   
   public function index() {
      return array();
   }
   
   public function register() {
      return array();
   }
   
   public function buildprofile() { /* THIS IS THE ONE I'D LIKE TO CALL */
      /* CandidateRegistrationForm::setDisplayLink("account/buildprofile") - tried this */
      return array();
   }
   
   public function editprofile() {
      return array();
   }
   
   function CandidateRegistrationForm() {
      $crf = new CandidateRegistrationForm($this, 'CandidateRegistrationForm');
      /* $crf->setDisplayLink("account/buildprofile"); - tried this too :) */
      return $crf;
   }
   
}

I open mysite/account/buildprofile and the first step displays nicely, but when I click Next... the URL redirects to /AccountController/CandidateRegistrationForm instead of /account/buildprofile/...

I get lost between controllers, forms and actions so I don't know where to go next, I'd appreciate any help.

Note: I did try calling the setDisplayLink("account/buildprofile") in the action method and setting it in the form method in the class as you can see above but I'm probably not getting something :)

Thank you, guys!