Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jennyfer 13 posts 126 karma points notactivated
    Mar 26, 2019 @ 12:39
    Jennyfer
    0

    How to manage Form Entry (edit/update)

    I am using Umbraco 7.13 and I made a request form and as per requirement, this can be editable at some point.

    My form includes file upload control and some textboxes.

    Please advise how to manage form entry (edit/update/delete) either in back office or frontend whichever is more secure.

    If you could also provide some documentations and examples will be very helpful as I am new to Umbraco.

    Thank you very much!

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Mar 26, 2019 @ 13:03
    Alex Skrypnyk
    0

    Hi Jennyfer

    You need to set AllowEditableFormSubmissions to true.

    You will find the UmbracoForms.config in the \App_Plugins\UmbracoForms the find the below, and change it to true

    <!-- Setting to true allows Form Submissions to be edited using ?recordId=GUID -->
    <!-- BEWARE! Enable this feature ONLY if you do understand the security implications. -->
        <setting key="AllowEditableFormSubmissions" value="True" />
    Hope this helps,
    

    Thanks,

    Alex

  • Jennyfer 13 posts 126 karma points notactivated
    Mar 26, 2019 @ 13:11
    Jennyfer
    0

    Hi Alex, thank you for the reply.

    I actually did that and it works fine but I noticed the Fileupload is not updated. I am not sure why.

    Please let me know if you have an idea on this.

    Thank you.

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Mar 26, 2019 @ 14:05
    Alex Skrypnyk
    0

    Not sure why, so when you upload a value first time - it works.

    If you try to edit it via backend - not?

  • Jennyfer 13 posts 126 karma points notactivated
    Mar 26, 2019 @ 14:12
    Jennyfer
    0

    Basically the edit is in the front-end, I added something like this : "?recordId=

    I have 2 upload files, initially only 1 is populated. So in my edit I populated the 2nd one. After submit, the first 1 got lost and only the 2nd one has the value. Everything else were updated.

    Is there a way to edit forms in backoffice? I saw only View and Delete actions but no Edit/Update.

    Please advise. Thank you very much.

  • Jennyfer 13 posts 126 karma points notactivated
    Apr 04, 2019 @ 15:14
    Jennyfer
    101

    I managed to solve the issue with the file upload edit. Not sure if this is the best way.

    This post helped with the idea: https://our.umbraco.com/forum/umbraco-forms/93241-umbraco-forms-custom-upload-field-store-string-value-of-file

            string fieldFolder = field.Id.ToString();
            string newFolder = DateTime.Now.ToUniversalTime().ToString("ddMMyyyyhhmmss");
            string dir = "/media/forms/" + fieldFolder + "/" + newFolder + "/";
    
            IList<HttpPostedFileBase> files = context.Request.Files.GetMultiple(field.Id.ToString());
    
            var existingFile = context.Request.Form[field.Id.ToString() + "_file"];
    
            foreach (HttpPostedFileBase file in files)
            {
                if (file.FileName != "")
                {
                    // Create directory
                    if (!Directory.Exists(HttpContext.Current.Server.MapPath(dir)))
                    {
                        Directory.CreateDirectory(HttpContext.Current.Server.MapPath(dir));
                    }
                    // Save the file
                    file.SaveAs(HttpContext.Current.Server.MapPath(dir + SafeURL(file.FileName)));
    
                    // Add string to the form       
                    myValue.Add(dir + SafeURL(file.FileName));
    
                    //force close the file to avoid error in accessing the file
                    file.InputStream.Close();
                    file.InputStream.Dispose();
                    GC.Collect();
    
    
                    // Remove any old file
                    if (existingFile != null)
                    { 
                        string oldDir = existingFile.Substring(0, existingFile.LastIndexOf("/"));
                        // Remove old directory
                        if (Directory.Exists(HttpContext.Current.Server.MapPath(oldDir)))
                        {
                            try
                            {
                                Directory.Delete(HttpContext.Current.Server.MapPath(oldDir), true);
                            }
                            catch
                            {
    
                            }
                        }
                    }
                }
            }
            // If nothing has been added but a previous value exists  add to the list
            if (myValue.Count() == 0 && existingFile != null)
            {
                myValue.Add(existingFile);
            }
    
            return myValue;
    
Please Sign in or register to post replies

Write your reply to:

Draft