2
votes

I am using code to create a form using Orchard.Forms. This is the code I have:

public void Describe(DescribeContext context) {
        Func<IShapeFactory, object> form =
            shape => {

                var f = Shape.Form(
                    Id: "MyLayoutBasicInformation",
                    _BasicInformation: Shape.Fieldset(
                        Title: T("Basic Information"),

                        _FirstName: Shape.TextBox(
                            Id: "FirstName", Name: "First Name",
                            Title: T("First Name"),
                            Description: T("The name for this field")
                            )
                        )
                    );
                return f;
            };
        context.Form("MyLayoutBasicInformation", form);
    }

Most of this type of code is used to render fields in the Admin UI. However, I am trying to render this in the front-end and have not been successful.

I tried using [Shape] but couldn't figure how to pull this into it. I also tried creating a .cshtml file, but I don't know what code to put into it either.

Any examples of how to render this form in the front-end? I know I can use Custom Forms to create a Content Type to render a form on the front-end using the Admin, but I am trying to do this with code.

Thank you in advance.

1

1 Answers

1
votes

You can inject IFormManager in your class and use it's Build method to build a new form.

        private readonly IFormManager _formManager;
        public YourClass(IFormManager formManager)
        {
             _formManager = formManager;
        }

and then call Build method like this :

var shape = _formManager.Build("MyLayoutBasicInformation");