문제

I created a new content type definition called SignUp with some text fields. Then i created a new custom form, with option Save the content item once the form is submitted selected an content type SignUp.

this works fine so far. But when i now create an entry and want to see it in admin at submissions, and click on the content item, i only seethis

What am I doing wrong? I don't even know if it saves the content item

도움이 되었습니까?

해결책

I assume you're using Orchard 1.7.2, because Custom Forms is broken in that way in this version (but it's already fixed in the 1.x branch, so it will work in Orchard 1.8 - coming soon).

The problem is basically how those content items are saved, but the data is not lost (and can be retrieved), just saved to the wrong table in the DB (ContentItemRecord, instead of ContentItemVersionRecord). See the issue on CodePlex for a description on how to apply a dirty fix that resolves this problem (the fix needs to be applied to the "CreatePOST" action in "Orchard.CustomForms/Controllers/ItemController".

Here is a piece of code that fixes the already existing submissions. You have to just place this controller into any module, e.g. Orchard.Users and then it will be available on the route "„~/Users/ContactFormEntryFix". If you place it in an other module then you'll have to edit the namespace and also you'll have to change the "_contentTypeId" property to the Id of the content type you use for your custom form:

using Orchard.ContentManagement;
using Orchard.ContentManagement.Records;
using Orchard.Data;
using Orchard.UI.Admin;
using System.Linq;
using System.Web.Mvc;

namespace Orchard.Users.Controllers
{
    [Admin]
    public class ContactFormEntryFixController : Controller
    {
        private readonly IRepository<ContentItemRecord> _contentItemRecords;
        private readonly IRepository<ContentItemVersionRecord> _contentItemVersionRecords;
        private readonly IContentManager _contentManager;
        private const int _contentTypeId = 26;


        public ContactFormEntryFixController(IRepository<ContentItemRecord> contentItemRecords, IRepository<ContentItemVersionRecord> contentItemVersionRecords, IContentManager contentManager)
        {
            _contentItemRecords = contentItemRecords;
            _contentItemVersionRecords = contentItemVersionRecords;
            _contentManager = contentManager;
        }


        public ActionResult Index()
        {
            var itemRecords = _contentItemRecords.Table.Where(record => record.ContentType.Id == _contentTypeId);
            var itemVersionRecords = _contentItemVersionRecords.Table.Where(versionRecord => itemRecords.Select(record => record.Id).Contains(versionRecord.ContentItemRecord.Id));

            foreach (var item in itemVersionRecords) item.Data = itemRecords.FirstOrDefault(record => record.Id == item.ContentItemRecord.Id).Data;

            var items = _contentManager.Query("ContactForm").List();
            foreach (var item in items) _contentManager.Unpublish(item);

            return Content(string.Format("{0} Contact Form version entry successfully fixed and {1} Contact Form item unpublished.", itemVersionRecords.Count(), items.Count()));
        }
    }
}

The submitted items are unpublished for security reasons (btw when using Custom Forms, make sure that the type you use is Draftable and of course they have to be saved upon submission, unless you use a workflow to handle their data).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top