コード例 #1
0
ファイル: OFormService.cs プロジェクト: dminik/voda_code
        private OFormResultRecord SaveFormToDB(OFormPart form, Dictionary<string, string> postData, HttpFileCollectionBase files, string ipSubmiter)
        {
            var xdoc = ConvertToXDocument(postData);
            var resultRecord = new OFormResultRecord
            {
                Xml = xdoc.ToString(),
                CreatedDate = DateTime.UtcNow,
                Ip = ipSubmiter,
                CreatedBy = postData[OFormGlobals.CreatedByKey]
            };

            if (form.CanUploadFiles && files.Count > 0)
            {
                foreach (string key in files.Keys)
                {
                    if (files[key].ContentLength == 0) { continue; }

                    CheckFileSize(form, files[key]);
                    CheckFileType(form, files[key]);

                    var formFile = SaveFile(key, files[key]);
                    resultRecord.AddFile(formFile);
                }
            }

            this._resultRepo.Create(resultRecord);
            form.Record.AddFormResult(resultRecord);
            _contentManager.Flush();

            return resultRecord;
        }
コード例 #2
0
		static void SetFormName(OFormPart formPart, string commonName, IOrchardServices orchardServices)
		{
			string formName = commonName;
			var i = -1;
			while (i++ < 10){
				if (i > 0){
					formName = string.Format("{0}-{1}", commonName, i);
				}
				
				var form = orchardServices.ContentManager.Query<OFormPart, OFormPartRecord>(VersionOptions.Latest)
					.Where(x => x.Name == formName)
					.List().FirstOrDefault();
				
				if (form == null) {
					break;
				}
			}
			
			formPart.Name = formName;
		}
コード例 #3
0
ファイル: OFormService.cs プロジェクト: homastudio/SnagIt
        public void SubmitForm(OFormPart form, Dictionary<string, string> postData, HttpFileCollectionBase files, string ipSubmiter)
        {
            if (form == null)
                throw new ArgumentNullException("form");
            if (postData == null)
                throw new ArgumentNullException("postData");

            var formResult = SaveFormToDB(form, postData, files, ipSubmiter);
            postData.Add("oforms.formResult.Id", formResult.Id.ToString());

            if (form.SendEmail) {
                _messageManager.Send(form.Record.ContentItemRecord,
                    MessageTypes.SendFormResult,
                    "email",
                    postData);
            }

            if (!form.SaveResultsToDB)
            {
                _resultRepo.Delete(formResult);
            }
        }
コード例 #4
0
		public static void PreFillForm(string templateName, OFormPart formPart, IOrchardServices orchardServices)
		{
			switch(templateName){
				case "ContactUs":
					SetFormName(formPart, "contact-us", orchardServices);
					formPart.Method = "POST";
					formPart.InnerHtml = @"<h2>Contact Us</h2>
<label for=""Name"">Name</label><br/>
<input name=""Name"" type=""text"" value="""" /><br/>

<label for=""Email"">Email</label><br/>
<input name=""Email"" type=""text"" value=""""/><br/>

<label for=""Phone"">Phone</label><br/>
<input name=""Phone"" type=""text"" value=""""/><br/>

<label for=""Website"">Website</label><br/>
<input name=""Website"" type=""text"" value=""""/><br/>

<label for=""Topic"">Topic of Inquiry</label><br/>
<input name=""Topic"" type=""text"" value=""""/><br/>

<label for=""Message"">Message</label><br/>
<textarea name=""Message"" cols=""50"" rows=""10""></textarea><br/>

<input type=""submit"" value=""Send"" /><br/>";
					formPart.SaveResultsToDB = true;
			        formPart.SuccessMessage = "Thank you for submitting the form";
					formPart.CanUploadFiles = false;
					formPart.SendEmail = false;
					formPart.ValRequiredFields = "Name, Email, Message, Topic";
					formPart.ValEmail = "Email";
					formPart.ValUrl = "Website";
					break;
			}
		}
コード例 #5
0
ファイル: OFormService.cs プロジェクト: homastudio/SnagIt
        private void CheckFileType(OFormPart form, HttpPostedFileBase postedFile)
        {
            if (string.IsNullOrEmpty(form.UploadFileType)) return;
            var fileTypes = form.UploadFileType.Split(new[] { ';', ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);

            if (!fileTypes.Any(ext => postedFile.FileName.EndsWith("." + ext, StringComparison.InvariantCultureIgnoreCase)))
            {
                throw new OrchardException(T("File type not supported: " + Path.GetExtension(postedFile.FileName)));
            }
        }
コード例 #6
0
ファイル: OFormService.cs プロジェクト: homastudio/SnagIt
 private void CheckFileSize(OFormPart form, HttpPostedFileBase postedFile)
 {
     if (postedFile.ContentLength / 1000 > form.UploadFileSizeLimit)
     {
         throw new OrchardException(T("File size exceeds allowed limit"));
     }
 }