London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

Xform form and custom file upload - how to store in database?

Vote:
 

I created a custom page type that is a mix of using a regular xform created in Edit mode, and I have added a custom file upload tool at the top of the page. I added a custom button submit, and on submit it stores the xform data using:

FormControl.SubmitForm(ChannelOptions.Database);

I've stored the file names uploaded into an array. How do I also add these files names (not actual files, just names) into the database? I'm not sure how I append to the database fields stored using ChannelOptions.

#33818
Oct 20, 2009 16:22
Vote:
 

Hi!

Try attaching to the BeforeSubmittingPostedData event for your XFormControl instance and set your file upload values direcly to the e.FormData object in your event arguments. Here´s a sample from the sdk:

e.FormData.SetValue("mycustomvalue", "12345");
Regards
Linus Ekström
EPiServer Development Team
#33825
Oct 20, 2009 20:26
Vote:
 

Thanks Linus!

I saw this in the SDK:

XForm form = new XForm();
XFormData data = form.CreateFormData();
NameValueCollection values = data.GetValues();
foreach(String key in values)
{
data.SetValue(key, "abc");
}
data.ChannelOptions = ChannelOptions.Database;
data.Send(); // In 4.51 you have to call data.Send(data.FormId);

 

 

But I didn't see anything about e.FormData.SetValue. I couldn't figure out how to add to the same form instead of a new form created.

#33827
Oct 20, 2009 21:01
Vote:
 
Oh that worked by the way, if I didn't say that earlier Laughing
#33828
Oct 20, 2009 21:02
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.