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   1418 Views

Avatar
lku

8 July 2011 at 2:10am Community Member, 8 Posts

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

8 July 2011 at 2:11am Community Member, 8 Posts

I forgot, i am using Silverstripe version 2.4.5

Avatar
swaiba

8 July 2011 at 3:59am Forum Moderator, 1796 Posts

Hi Iku,

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

Avatar
lku

8 July 2011 at 7:48pm Community Member, 8 Posts

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

8 July 2011 at 8:35pm Forum Moderator, 1796 Posts

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

8 July 2011 at 8:44pm Community Member, 8 Posts

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

8 July 2011 at 8:52pm Forum Moderator, 1796 Posts

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

Avatar
lku

8 July 2011 at 8:58pm Community Member, 8 Posts

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