mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 21:01:35 +08:00
Correcting lost form values when a comment is not valid
Work Item: 16817 --HG-- branch : dev
This commit is contained in:
parent
fe9225ce8a
commit
1918a78646
@ -7,8 +7,6 @@ using Orchard.Comments.ViewModels;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Localization;
|
||||
using Orchard.UI.Notify;
|
||||
using Orchard.Utility.Extensions;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Orchard.Comments.Controllers {
|
||||
public class CommentController : Controller {
|
||||
@ -33,16 +31,19 @@ namespace Orchard.Comments.Controllers {
|
||||
: Redirect("~/");
|
||||
|
||||
var viewModel = new CommentsCreateViewModel();
|
||||
|
||||
if (TryUpdateModel(viewModel)) {
|
||||
var context = new CreateCommentContext {
|
||||
Author = viewModel.Name,
|
||||
CommentText = viewModel.CommentText,
|
||||
Email = viewModel.Email,
|
||||
SiteName = viewModel.SiteName,
|
||||
CommentedOn = viewModel.CommentedOn
|
||||
};
|
||||
|
||||
TryUpdateModel(viewModel);
|
||||
|
||||
var context = new CreateCommentContext {
|
||||
Author = viewModel.Name,
|
||||
CommentText = viewModel.CommentText,
|
||||
Email = viewModel.Email,
|
||||
SiteName = viewModel.SiteName,
|
||||
CommentedOn = viewModel.CommentedOn
|
||||
};
|
||||
|
||||
|
||||
if (ModelState.IsValid) {
|
||||
if (!String.IsNullOrEmpty(context.SiteName) && !context.SiteName.StartsWith("http://") && !context.SiteName.StartsWith("https://")) {
|
||||
context.SiteName = "http://" + context.SiteName;
|
||||
}
|
||||
@ -58,6 +59,13 @@ namespace Orchard.Comments.Controllers {
|
||||
}
|
||||
}
|
||||
|
||||
if(!ModelState.IsValid) {
|
||||
TempData["CreateCommentContext.Name"] = context.Author;
|
||||
TempData["CreateCommentContext.CommentText"] = context.CommentText;
|
||||
TempData["CreateCommentContext.Email"] = context.Email;
|
||||
TempData["CreateCommentContext.SiteName"] = context.SiteName;
|
||||
}
|
||||
|
||||
return !String.IsNullOrEmpty(returnUrl)
|
||||
? Redirect(returnUrl)
|
||||
: Redirect("~/");
|
||||
|
@ -3,6 +3,14 @@
|
||||
@using Orchard.Security;
|
||||
@using Orchard.Utility.Extensions;
|
||||
|
||||
@{
|
||||
var contextExists = TempData["CreateCommentContext.Name"] != null;
|
||||
var name = Convert.ToString(TempData["CreateCommentContext.Name"]);
|
||||
var commentText = Convert.ToString(TempData["CreateCommentContext.CommentText"]);
|
||||
var email = Convert.ToString(TempData["CreateCommentContext.Email"]);
|
||||
var siteName = Convert.ToString(TempData["CreateCommentContext.SiteName"]);
|
||||
}
|
||||
|
||||
@if (Model.ContentPart.Comments.Count > 0) {
|
||||
<div id="comments">
|
||||
<h2 class="comment-count">@T.Plural("1 Comment", "{0} Comments", (int)Model.ContentPart.Comments.Count)</h2>
|
||||
@ -30,15 +38,15 @@ using (Html.BeginForm("Create", "Comment", new { area = "Orchard.Comments" }, Fo
|
||||
<ol>
|
||||
<li>
|
||||
<label for="Name">@T("Name")</label>
|
||||
<input id="Name" class="text" name="Name" type="text" />
|
||||
<input id="Name" class="text" name="Name" type="text" value="@(contextExists ? name : String.Empty)" />
|
||||
</li>
|
||||
<li>
|
||||
<label for="Email">@T("Email")</label>
|
||||
<input id="Email" class="text" name="Email" type="text" />
|
||||
<input id="Email" class="text" name="Email" type="text" value="@(contextExists ? email : String.Empty)"/>
|
||||
</li>
|
||||
<li>
|
||||
<label for="SiteName">@T("Url")</label>
|
||||
<input id="SiteName" class="text" name="SiteName" type="text" />
|
||||
<input id="SiteName" class="text" name="SiteName" type="text" value="@(contextExists ? siteName : String.Empty)"/>
|
||||
</li>
|
||||
</ol>
|
||||
</fieldset>
|
||||
@ -52,7 +60,7 @@ using (Html.BeginForm("Create", "Comment", new { area = "Orchard.Comments" }, Fo
|
||||
<ol>
|
||||
<li>
|
||||
<label for="comment-text">@T("Comment")</label>
|
||||
<textarea id="comment-text" rows="10" cols="30" name="CommentText"></textarea>
|
||||
<textarea id="comment-text" rows="10" cols="30" name="CommentText">@(contextExists ? commentText : String.Empty)</textarea>
|
||||
</li>
|
||||
<li>
|
||||
<button class="primaryAction" type="submit">@T("Submit Comment")</button>
|
||||
|
Loading…
Reference in New Issue
Block a user