hi,
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 );
$fields->push($birthdayfield);
$actions = new FieldSet(
new FormAction('SaveEditProfileForm','Speichern')
);
$validator = new RequiredFields('salutation','FirstName','Surname');
$Form = new Form($this, 'EditProfileForm', $fields, $actions, $validator);
$Member = Member::CurrentMember();
$Form->loadDataFrom($Member->data());
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?
$Form->loadDataFrom($Member->data());
thx
daniel