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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Error reporting with redirectBack


Go to End


3 Posts   671 Views

Avatar
Martinjj

Community Member, 12 Posts

18 December 2013 at 3:43am

Edited: 18/12/2013 3:44am

Hello, i am having issues with showing an error when a user registers an account using an "in use" email address.

I am updating Arams site members code

I have reworked the deprecated code and now it all functions well other than showing the error message on duplicated email used at registration.

//Check for existing member email address
		if($member = DataObject::get_one("Member", "`Email` = '". Convert::raw2sql($data['Email']) . "'")) 
		{
			//Set error message
			$form->AddErrorMessage('Email', "Sorry, that email address already exists. Please choose another.", 'bad');
			//Set form data from submitted values
			Session::set("FormInfo.Form_RegistrationForm.data", $data);		
			//Return back to form
			return $this->redirectBack();			
		}

the code catches the duplicated email on sending, but fails to show the error message on redirectBack, im quite new to this but i would not have thought redirectback would be a typical approach as basicaly the page is just refreshing.

i have tried return $this->redirectBack('Email); amongst other shots in the dark and having no success.
regards

Avatar
swaiba

Forum Moderator, 1899 Posts

18 December 2013 at 4:25am

Instead of just relying on...

$validator = new RequiredFields('FirstName', 'Email', 'Password');

create a more complex validator that does your validation - then no need to do the validation in the submit (and hence no need to use redirect back). This is a post that addresses their use within ModelAdmin... And it is [kinda] the same for a form.

http://www.silverstripe.org/general-questions/show/17007

Avatar
Martinjj

Community Member, 12 Posts

18 December 2013 at 5:06am

Brilliant thanks... funnily enough i have just been checking this out on the docs http://doc.silverstripe.org/framework/en/topics/datamodel which under "Validation and Constraints" shows a similar way as yours..
cheers