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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Form Questions /

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

Custom form with custom validation


Go to End


3 Posts   1576 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