File Upload On Alternative Form

Matt Swain asked on November 23, 2014 16:39

Hi Support,

I am using the DataForm control to create an edit page for a user to be able to edit a custom document type.

I have set a field up within the custom document type as a 'File' type and chosen the 'Upload File' control, this brings it out correclty on the page and I can choose an image. So far so good.

Unforunately when I submit the form, the rest of the form saves (if I update the name or the email address etc.), but the file upload control doesn't seem to do anything. It doesn't upload a file and it doesn't set anything in the database.

Any ideas what i'm doing wrong? Do I need to set something else for this to work? I'm asuming this form control should work inside an alternative form?

I am using a CMS:DataForm to load in the form with and setting the ItemID and the AlternativeFormName. The form loads correctly with the data and the other fields do update correctly, it's just the file upload that doesn't seem to do anything.

Thanks,

Matt

Recent Answers


Joshua Adams answered on November 24, 2014 16:30

Do you have the form wrapped in an update panel? This would wipe the value of the control out before the save action.

0 votesVote for this answer Mark as a Correct answer

Matt Swain answered on November 24, 2014 16:33

Hi Josh,

No I don't. I even took out all my back end logic just in case I was reloading the page or something as I had a similair thought.

<cms:DataForm runat="server" ID="dataFormDriver" ClassName="CLASSNAME" ItemID="1" AlternativeFormFullName="FORM" />

is literally at the moment all that is in my web part to test if it works (editing item 1).

Thanks,

Matt

0 votesVote for this answer Mark as a Correct answer

Joshua Adams answered on November 24, 2014 22:47

Have you tried setting enableviewstate to true?

0 votesVote for this answer Mark as a Correct answer

Josef Dvorak answered on November 26, 2014 17:20 (last edited on November 26, 2014 17:21)

Hi,

We have been resolving this question with Matt via email. In the end we used a different control that is better suited for this purpose:

<cms:CMSForm ID="cmsForm" runat="server" IsLiveSite="true" />

With one of these this setup method called from OnInit handler for Edit dialog:

protected bool ShowEditForm(string aliasPath = "/aaPage")
{
    NodeSelectionParameters parameters = new NodeSelectionParameters()
    {
        AliasPath = aliasPath,
        CultureCode = "en-US",
        CombineWithDefaultCulture = true,
        ClassNames = "custom.aaCustom"
    };

    TreeProvider tree = new TreeProvider();

    var editedObject = tree.SelectSingleNode(parameters);

    //var editedObject = DocumentHelper.GetDocument(parameters, new TreeProvider());
    if (editedObject == null)
    {
        LogInfo("No object found");
        return false;
    }
    LogInfo("Object: " + editedObject.TypeInfo.ObjectClassName);

    FormInfo formInfo = FormHelper.GetFormInfo("custom.aaCustom", true);
    if (formInfo == null)
    {
        LogInfo("No form found");
        return false;
    }
    LogInfo("Form: " + formInfo.ItemsList.Count + " fields");


    cmsForm.DocumentManager.Mode = FormModeEnum.Update;
    cmsForm.NodeID = editedObject.NodeID;
    cmsForm.LoadForm(true);
    cmsForm.SubmitButton.Visible = true;

    return true;
}

Or this one for new Page dialogue.

protected bool ShowInsertForm()
{
    //var editedObject = UserInfoProvider.GetUserInfo("administrator");

    NodeSelectionParameters parameters = new NodeSelectionParameters()
    {
        AliasPath = "/aaPage",
        CultureCode = "en-US",
        CombineWithDefaultCulture = true,
        ClassNames = "custom.aaCustom"
    };

    TreeProvider tree = new TreeProvider();

    var editedObject = tree.SelectSingleNode(parameters);

    //var editedObject = DocumentHelper.GetDocument(parameters, new TreeProvider());
    if (editedObject == null)
    {
        LogInfo("No object found");
        return false;
    }
    LogInfo("Object: " + editedObject.TypeInfo.ObjectClassName);

    FormInfo formInfo = FormHelper.GetFormInfo("custom.aaCustom", true);
    if (formInfo == null)
    {
        LogInfo("No form found");
        return false;
    }
    LogInfo("Form: " + formInfo.ItemsList.Count + " fields");

    DataClassInfo documentClass = DataClassInfoProvider.GetDataClassInfo(CurrentPageInfo.NodeClassID);
    if (documentClass == null)
    {
        LogInfo("No class found");
        return false;
    }
    LogInfo("Class: " + documentClass.ClassName);

    cmsForm.DocumentManager.Mode = FormModeEnum.Insert;
    cmsForm.DocumentManager.NodeID = 0;
    cmsForm.DocumentManager.ParentNodeID = CurrentDocument.NodeID;
    cmsForm.DocumentManager.NewNodeClassID = CurrentPageInfo.NodeClassID;
    cmsForm.FormName = cmsForm.DocumentManager.NewNodeClassName + ".default";
    cmsForm.LoadForm(true);
    cmsForm.SubmitButton.Visible = true;

    return true;
}
1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.