Form Question...Action/Save

Topics: Customizing Orchard
Nov 10, 2011 at 1:17 PM

Hi,

 

I create an html form in body part in a page like this:

<form method="post" action="action/save"><input name="Text1" type="text" /> <input name="Text2" type="text" /> <input name="Submit1" value="submit" type="submit" /></form>

URL: http://localhost:30320/OrchardLocal/forminput

When I push submit button, Orchard goes right to http://localhost:30320/OrchardLocal/action/save

So. Where Do I create controller? Which are the rights steps?

Nov 10, 2011 at 2:13 PM

If you're not familiar with MVC controllers then perhaps the best place to start is with some MVC tutorials. Once you understand the concepts of controllers, actions and MVC forms in general, it's much easier to start applying that to an Orchard module.

Getting started with MVC 3: http://www.asp.net/mvc/tutorials/getting-started-with-mvc3-part1-cs

MVC music store (advanced): http://www.asp.net/mvc/tutorials/mvc-music-store-part-1

Nov 11, 2011 at 7:32 AM

I understand MVC concept, but I wish to know how to create form in Orchard and wish the best and fast method. I see that there are new API Form but there is not documentation, now.

Have you step by step example or code?

Thanks

Nov 11, 2011 at 12:19 PM

You'll have to follow the existing examples, e.g. in the Rules module. I haven't played with it myself yet. But you were asking about controllers which made me think you weren't sure about the MVC side of things. You can just use the normal MVC way to create forms and link them to your controllers (e.g. @Html.BeginForm etc.)

Nov 11, 2011 at 2:30 PM

So, I've created:

 

@model HelloWorld.ViewModels.HelloWorldFormViewModel
@{
	Layout.Title = "Contact Us";
}

<h1>@Layout.Title</h1>

@using (Html.BeginFormAntiForgeryPost()) {
	<fieldset>
		<p>@Html.LabelFor(m => m.Name)
			@Html.TextBoxFor(m => m.Name)
			@Html.ValidationMessageFor(m => m.Name)</p>

		<p>@Html.LabelFor(m => m.Email)
			@Html.TextBoxFor(m => m.Email)
			@Html.ValidationMessageFor(m => m.Email)</p>

		<p>@Html.LabelFor(m => m.Message)
			@Html.TextAreaFor(m => m.Message, new { Cols = 50, Rows = 8 })
			<br />@Html.ValidationMessageFor(m => m.Message)</p>

		<p><input class="button primaryAction" type="submit" value="@T("Send")" /></p>
	</fieldset>
}

then, into the controller, I need to create post branch?