Jump to:

1973 Posts in 1275 Topics by 608 members

Form Questions

SilverStripe Forums » Form Questions » data loss after form sent

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

Page: 1 2
Go to End
Author Topic: 1200 Views
  • lku
    Avatar
    Community Member
    8 Posts

    data loss after form sent Link to this post

    Hello everyone,

    can anybody point me at a solution how to persist data from form, when this form is sent and something failed, validation for example?

    Simple example:
    I have DataObject bounded to Page with one to many relationship like in this doc: http://doc.silverstripe.org/sapphire/en/tutorials/5-dataobject-relationship-management.

    If one of this fields: http://doc.silverstripe.org//src/sapphire_2.4/docs/en/tutorials/_images/gsoc-student-creation.jpg would be required (for example First Name) and i try to add new student without filling this required field, whole form will be submited, an error message will show up and all data from form are lost. How can I prevent this behaviour?

  • lku
    Avatar
    Community Member
    8 Posts

    Re: data loss after form sent Link to this post

    I forgot, i am using Silverstripe version 2.4.5

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts
  • lku
    Avatar
    Community Member
    8 Posts

    Re: data loss after form sent Link to this post

    Hi swaiba,

    thanks for your answer, in my case, I found data from my form in

    Session::get('FormInfo.BannerDataObjectManager_Popup_AddForm.data');

    But I don't know how can I access form object in DataObject::getCMSFields method. It is possible anyway?

    There is only FormField::setValue method (or constructor third parameter) on field object, but this is not working, neither FieldSet::setValues. I think, this is not working, because values are overwritten in Form::loadDataFrom and thats called from CMSMain::getEditForm.

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: data loss after form sent Link to this post

    But I don't know how can I access form object in DataObject::getCMSFields method. It is possible anyway?
    I think you should be able to access the session at any point, but I don't know if there will be anything in it... that specfication is new to me.

    Personally I have never had this issue within the CMS, using plain model admin by creating my own validator and I don't need to worry about the session stuff....
    http://silverstripe.org/general-questions/show/17007#post303679

  • lku
    Avatar
    Community Member
    8 Posts

    Re: data loss after form sent Link to this post

    I think you should be able to access the session at any point, but I don't know if there will be anything in it... that specfication is new to me.
    Yes, yes, I can access session data, thats not a problem (and thanks for info about this).

    Validation works too, but if form validation failed (for example, i don't fill required field), every data I filled in form are lost and I have to fill whole form again and thats annoying - especially for my client )

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: data loss after form sent Link to this post

    I think it's a DOM issue then... So I'd encourage you to post in that section...

  • lku
    Avatar
    Community Member
    8 Posts

    Re: data loss after form sent Link to this post

    Oh, and is there way to move this topic to another section, or may I submit new?

    Swaiba, anyway, thanks for your help with analysing my problem!

    1200 Views
Page: 1 2
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.