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

Custom form with custom validation


Go to End


3 Posts   2031 Views

Avatar
Jatinder

Community Member, 23 Posts

25 August 2010 at 2:19pm

Hello,

I am implemented a custom form with a custom template and it works fine.

Besides other fields, the form has two phone number fields. I need to implement a validation "Input at least one phone number".

How do I go about this?

Thanks,
Jatinder

Avatar
Jatinder

Community Member, 23 Posts

26 August 2010 at 4:56pm

Would appreciate some help. Please respond!

Avatar
patjnr

Community Member, 102 Posts

26 August 2010 at 7:38pm

Hi

Hope this will help you

function submit($data, $form) {
	
		
		
		if(empty($data['tel_1'])  && empty($data['Tel_2'] ) ) {
			$form->addErrorMessage("tel_1",_t("ContactForm.TELEPHONEERROR","Please enter at least one Tel number."),"bad");
			// Load errors into session and post back
			Session::set("FormInfo.Form_ContactForm.data", $data);
			return Director::redirectBack();
			
		}

this should work

PAt