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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

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

Multiform module doesnt not prepopulate form on validation error


Go to End


807 Views

Avatar
fpereira1

Community Member, 1 Post

17 December 2013 at 8:49am

Edited: 17/12/2013 8:55am

I am building a custom validation for the multiform module

I am using version 3.0.8 but have also tried on branch 1.0

My steps to reproduce this issue are:

* on ExampleMultiFormEligibility type in a country and in ResidencyStatus type resident
* on the next page click back button on the form
* change resident to "test"
(a this point it will fail the validation ExampleMultiFormEligibility_Validator)
* The ExampleMultiFormEligibility form is built, the value I typed "test" is lost and my previous value "resident" (the one saved on the DB) is loaded into the form

The expected result would be that if the validation failed, the form should load and the "test" string appear in the form through Session data.

Anyone else has had a similar issue?

The example code I've used is the one below:

<?php

class ExampleMultiForm extends MultiForm {

	 public static $start_step = 'ExampleMultiFormEligibility';

}

class ExampleMultiFormStep extends MultiFormStep {
}

class ExampleMultiFormEligibility extends ExampleMultiFormStep {

	public static $next_steps = 'ExampleMultiFormDetails';

	/**
	 * [getFields description]
	 * @return [type] [description]
	 */
	public function getFields() {
		return new FieldList(
			new TextField('Country', 'Country'),
			new TextField('ResidencyStatus', 'Residency status')
		);
	}

	public function getValidator() {
		return new ExampleMultiFormEligibility_Validator();
	}

}

class ExampleMultiFormEligibility_Validator extends Validator {

	const ERROR = 'error';

	public function php($data) {

		$valid = true;

		if($data['ResidencyStatus'] != 'resident') {
			$valid = false;
			$this->validationError('ResidencyStatus', 'Residency status must be resident', self::ERROR);
		}

		return $valid;
	}

}