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.

Form Questions /

data loss after form sent


Go to End
Reply


9 Posts   1431 Views

Avatar
lku

Community Member, 8 Posts

8 July 2011 at 2:10am

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?

Avatar
lku

Community Member, 8 Posts

8 July 2011 at 2:11am

I forgot, i am using Silverstripe version 2.4.5

Avatar
swaiba

Forum Moderator, 1798 Posts

8 July 2011 at 3:59am

Hi Iku,

this might help...
http://www.silverstripe.org/form-questions/show/16740#post302709

Avatar
lku

Community Member, 8 Posts

8 July 2011 at 7:48pm

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.

Avatar
swaiba

Forum Moderator, 1798 Posts

8 July 2011 at 8:35pm

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

Avatar
lku

Community Member, 8 Posts

8 July 2011 at 8:44pm

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 :))

Avatar
swaiba

Forum Moderator, 1798 Posts

8 July 2011 at 8:52pm

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

Avatar
lku

Community Member, 8 Posts

8 July 2011 at 8:58pm

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!

Go to Top