mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 10:54:50 +08:00
Correcting lost form values when a comment is not valid
Work Item: 16817 --HG-- branch : dev
This commit is contained in:
@@ -7,8 +7,6 @@ using Orchard.Comments.ViewModels;
|
|||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
using Orchard.UI.Notify;
|
using Orchard.UI.Notify;
|
||||||
using Orchard.Utility.Extensions;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
|
|
||||||
namespace Orchard.Comments.Controllers {
|
namespace Orchard.Comments.Controllers {
|
||||||
public class CommentController : Controller {
|
public class CommentController : Controller {
|
||||||
@@ -34,15 +32,18 @@ namespace Orchard.Comments.Controllers {
|
|||||||
|
|
||||||
var viewModel = new CommentsCreateViewModel();
|
var viewModel = new CommentsCreateViewModel();
|
||||||
|
|
||||||
if (TryUpdateModel(viewModel)) {
|
TryUpdateModel(viewModel);
|
||||||
var context = new CreateCommentContext {
|
|
||||||
Author = viewModel.Name,
|
|
||||||
CommentText = viewModel.CommentText,
|
|
||||||
Email = viewModel.Email,
|
|
||||||
SiteName = viewModel.SiteName,
|
|
||||||
CommentedOn = viewModel.CommentedOn
|
|
||||||
};
|
|
||||||
|
|
||||||
|
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://")) {
|
if (!String.IsNullOrEmpty(context.SiteName) && !context.SiteName.StartsWith("http://") && !context.SiteName.StartsWith("https://")) {
|
||||||
context.SiteName = "http://" + context.SiteName;
|
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)
|
return !String.IsNullOrEmpty(returnUrl)
|
||||||
? Redirect(returnUrl)
|
? Redirect(returnUrl)
|
||||||
: Redirect("~/");
|
: Redirect("~/");
|
||||||
|
@@ -3,6 +3,14 @@
|
|||||||
@using Orchard.Security;
|
@using Orchard.Security;
|
||||||
@using Orchard.Utility.Extensions;
|
@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) {
|
@if (Model.ContentPart.Comments.Count > 0) {
|
||||||
<div id="comments">
|
<div id="comments">
|
||||||
<h2 class="comment-count">@T.Plural("1 Comment", "{0} Comments", (int)Model.ContentPart.Comments.Count)</h2>
|
<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>
|
<ol>
|
||||||
<li>
|
<li>
|
||||||
<label for="Name">@T("Name")</label>
|
<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>
|
||||||
<li>
|
<li>
|
||||||
<label for="Email">@T("Email")</label>
|
<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>
|
||||||
<li>
|
<li>
|
||||||
<label for="SiteName">@T("Url")</label>
|
<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>
|
</li>
|
||||||
</ol>
|
</ol>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
@@ -52,7 +60,7 @@ using (Html.BeginForm("Create", "Comment", new { area = "Orchard.Comments" }, Fo
|
|||||||
<ol>
|
<ol>
|
||||||
<li>
|
<li>
|
||||||
<label for="comment-text">@T("Comment")</label>
|
<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>
|
||||||
<li>
|
<li>
|
||||||
<button class="primaryAction" type="submit">@T("Submit Comment")</button>
|
<button class="primaryAction" type="submit">@T("Submit Comment")</button>
|
||||||
|
Reference in New Issue
Block a user