Reputation: 753
I'd like to create a custom content type used in a form that has fields that behave differently when edited on the custom form page than from within the admin backend. The form will allow visitors to sign up to be notified when an online publication changes. I plan on using the form within an iframe
inside another application.
Custom Content Type Fields
For users filling out the form on the custom form page (As opposed to creating a new content item from within the admin backend) I'd like to change the behavior of a few of the fields:
ProductId
field (type text) should not be editable or visible and should get its value from a query string variableSubscribeDate
field should not be editable or visible and should be automatically set to the date the form is submittedCancelDate
field should not be editable or visibleIsActive
field should not be editable or visible and should be automatically set to trueI'm new to Orchard and at first I was thinking about creating custom fields or custom parts or alternate views for the fields that used hidden inputs. After writing down the question I think I have a good solution but I'd like to know if there's a better way.
Possible Solution
FirstName
, LastName
, Occupation
, Email
, and PublicationId
. text input
element for PublicationId
use a hidden input
that gets its value from a query string variable. Alternatively, create a custom view for just the PublicationId
field.SubscribeDate
and IsActive
. I'm not sure how much control I have in Workflows, so alternatively create a handler for the form submission (does this exists?) that creates an instance of the custom content type above and sets the defaults.Am I headed in the right direction? And should I create the custom content types in the admin UI or in code? I would like all my code related to this publication notification feature to be all in one spot so writing a module makes sense. Some other parts of this feature will be:
Thanks! Any input is greatly appreciated.
Upvotes: 0
Views: 839
Reputation: 160
I think that you'll need to create a new content part, this content part should contain those fields (all of them). This part should be assigned to the new content type.
Create a field for the part (migrations)...
ContentDefinitionManager.AlterPartDefinition("YourPartName",
builder => builder.WithField("YourFieldName", fieldBuilder => fieldBuilder.OfType("TextField").WithDisplayName("Your field name")));
After adding all the desired fields you should attach the new part to the new content type...
ContentDefinitionManager.AlterTypeDefinition("YourContentTypeName",
builder => builder.WithPart("YourPartName"));
Tip: Always use migrations, they allow you to have control and if you're working on different environments you'll have the same structure without having to create again the same parts/content types.
I recommend you to take a look at parts and drivers.
Hope this helps.
Regards.
Upvotes: 1