Umbraco Forms - Basics
Umbraco Forms Introduction:
a) Stores the forms in the /App_Plugins/UmbracoForms/Data/forms/ folder
b) Stores the forms in JSON format
c) Gives each form a GUID, such as: ea-3e73-4b99-9d81-3055149e3c2e.json that can be used to reference the forms.
In the main umbraco template add links to,
- JQUERY,
- Jquery Validation
- Jquery Unobtrusive Validation
EX:
<!-- Javascripts -->
<script src="/js/jquery.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
<script src="/scripts/fanoe.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.14.0/jquery.validate.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/mvc/5.2.3/jquery.validate.unobtrusive.js"></script>
Umbraco Forms, list Forms from Directory:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage@using System.Xml.XPath
@using System.IO;
@{
Layout = "Master.cshtml";
}
@{
var request = HttpContext.Current.Request;
string url = Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery,
string.Empty);
<p>url: @url</p>
foreach(var fileName in Directory.GetFiles(Server.MapPath("~/App_Plugins/UmbracoForms/Data/forms/")))
{
<p>@fileName</p>
}
}
Umbraco Forms,Render All Availble forms on to a Page:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@using System.Xml.XPath
@using System.IO;
@using System.Net;
@using Newtonsoft.Json;
@using Newtonsoft.Json.Linq;
@{
Layout = "Master.cshtml";
}
@{
var request = HttpContext.Current.Request;
string url = Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery,
string.Empty);
foreach(var fileName in Directory.GetFiles(Server.MapPath("~/App_Plugins/UmbracoForms/Data/forms/")))
{
var jsonFileUrl = @fileName;
string extension = Path.GetExtension(@jsonFileUrl);
WebClient wc = new WebClient();
var json = (JObject)JsonConvert.DeserializeObject(wc.DownloadString(jsonFileUrl));
var formName = json["name"].ToString();
var formGuid = json["id"].ToString();
<p><a href="@jsonFileUrl">@formName</a></p>
<div>
@Umbraco.RenderMacro("FormsRenderForm", new {FormGuid= @formGuid})
</div>
}
}
Comments
Post a Comment