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.

Form Questions /

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

Augmenting Validation on Subclassed Custom Forms


Go to End


1072 Views

Avatar
zenmonkey

Community Member, 545 Posts

19 February 2013 at 3:09am

I have a cusrtom form, with multiple subclasses forms that I want to augment the Validation porion on the sublcasses, but I'm not sure how to go about it.

The Custom Form

class LeadCaptureForm extends Form {
	
	public function __construct($controller, $name) {


		$fields = new FieldList(
			$holder
		);
		
		$actions = new FieldList(
		   FormAction::create("leadSubmit")->setTitle($controller->FormButton)->setUseButtonTag(true)->addExtraClass('button red small point-right')
		);
		
		
		$validation = new RequiredFields(array('Email'));
		
		parent::__construct($controller, $name, $fields, $actions, $validation);
	
	}

The sublcassed forms look like this

class MarketForm extends LeadCaptureForm {
	function __construct($controller, $name) {
		 
		parent::__construct($controller, $name);

		$newfields = new CompositeField(
			$house,
			$homedeet,
			$propDeets
		);
		
		$this->Fields()->insertBefore($newfields, "main");
		
		
	}
}

On the MarketForm I'd like to add a few of the LeadCaptureForms to the validation as well as the the fields from MarketForm.