Jump to:

1999 Posts in 1408 Topics by 613 members

Form Questions

SilverStripe Forums » Form Questions » EditProfileForm not holding correct values after submit wiht errors in form

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

Page: 1
Go to End
Author Topic: 718 Views
  • danzzz
    Avatar
    Community Member
    175 Posts

    EditProfileForm not holding correct values after submit wiht errors in form Link to this post

    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

  • swaiba
    Avatar
    Forum Moderator
    1784 Posts

    Re: EditProfileForm not holding correct values after submit wiht errors in form Link to this post

    in EditProfileForm(...

          if(Session::get("FormData"))
          {
             $previous_value = Session::get("FormData");
             Session::clear("FormData");
             $form->loadDataFrom($previous_value);
          }

    in SaveEditProfileForm...

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

  • danzzz
    Avatar
    Community Member
    175 Posts
    718 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.