I am trying to do server side validation with custom validation for the phone and email fields. I am doing the custom validation in the forms action.
Firstly is this the correct place to do it and secondly if so how can I get the data to return to the form if it doesn't meet validation?
Currently it will clear the entire form.
public function doSubmitForm($data, Form $form) {
if (!preg_match("/^[\+_a-z0-9-'&=]+(\.[\+_a-z0-9-']+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$/i",$data['Email'])) {
$form->addErrorMessage('Email', 'Invalid email', 'bad');
return $this->redirectBack();
}
if (!preg_match("/^((?:\+)|0)(\d{9,14})$/i",$data['Phone'])) {
$form->addErrorMessage('Phone', 'Please match the correct format eg: 0821234567', 'bad');
return $this->redirectBack();
}
$form->sessionMessage('Thank you for your submission','alert alert-success');
return $this->redirectBack();
}