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.

Form Questions /

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

Augmenting Validation on Subclassed Custom Forms

Go to End



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(
		$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(
		$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.