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

EditProfileForm not holding correct values after submit wiht errors in form

Go to End

3 Posts   1068 Views


Community Member, 175 Posts

3 May 2011 at 1:58am


I have a form where users can edit their profile.

public function EditProfileForm() {

	$fields = new FieldSet(
	    new DropdownField('salutation', 'Anrede',singleton('Member')->dbObject('salutation')->enumValues()),
	    new TextField('FirstName','Vorname'),
	    new TextField('Surname','Nachname'),
	    new TextField('street','Straße, Hnr.'),
	    new TextField('zip','PLZ'),
	    new TextField('city','Ort'),
	    new DropdownField('country', 'Land',singleton('Member')->dbObject('country')->enumValues()),
	    new TextField('telephone', 'Telefonnummer')

	$birthdayfield = new DateField('birthday','Geburtstag');
	$birthdayfield->setConfig('dmyfields', true );

	$actions = new FieldSet(
	    new FormAction('SaveEditProfileForm','Speichern')

	$validator = new RequiredFields('salutation','FirstName','Surname');

	$Form = new Form($this, 'EditProfileForm', $fields, $actions, $validator);

	$Member = Member::CurrentMember();

        return $Form;


This form works as expacted, but not when there is an error, for example no FirstName ...
There are also other fields on the form, which are not required. An example:
The user fills out all fields and deletes FirstName before submit, so there will be an error because FirstName is required.

The error appears, but all the fields the user filled out are empty again after submit.

How to avoid this? It's bad that the user must start again filing out the form.

I think this line must be changed when it's a post?




Forum Moderator, 1899 Posts

3 May 2011 at 11:43pm

in EditProfileForm(...

			$previous_value = Session::get("FormData");

in SaveEditProfileForm...

		Session::set("FormData", $data);


Community Member, 175 Posts

7 May 2011 at 3:06am

thx, did it that way ...