如何自定义Sitefinity默认MVC表单部件的HTML格式感谢消息?
Customizing Sitefinity MVC Form Thank You Message with HTML
Hey there! I’ve dealt with this exact issue with Sitefinity’s default MVC form widget before—those plain-text thank you messages are totally inflexible when you want to add styling or custom content. Let’s get you set up with HTML-enabled thank you content using two straightforward methods:
Method 1: Use a Custom Form Template (No Code Needed, Recommended)
This is the easiest approach for most cases, especially if you don’t want to dive into code:
- Log into your Sitefinity backend, navigate to your test form, and go to the Design tab
- Click Templates > Create New Template, give it a descriptive name (like
StyledThankYouFormTemplate) - In the template editor, locate the section that renders the thank you message (usually wrapped in a
<div class="sfFormThankYouMessage">container) - Replace the default plain-text placeholder with your custom HTML. For example:
<div class="custom-thank-you-container"> <h3>🎉 Your Form Was Submitted Successfully!</h3> <p>We’ll reach out to you within 24 hours—<strong>keep an eye on your email</strong> for updates.</p> <a href="/our-services" class="cta-button">Explore Our Services</a> </div> - Save the template, then head to the form’s Layout tab. Replace the default form widget with one that uses your new custom template
- Test submitting the form, and you’ll see your styled HTML thank you message live
Method 2: Extend with Backend Code (For Dynamic Content)
If you need to generate dynamic thank you content (like using the user’s submitted data), you can extend the default form controller:
- In your Sitefinity project, create a new MVC widget that inherits from Sitefinity’s built-in
FormController - Override the
SubmitFormmethod to replace the plain-text thank you message with your HTML. Here’s a quick example:protected override ActionResult SubmitForm(FormViewModel viewModel) { // Run the default form submission logic first var baseResult = base.SubmitForm(viewModel); // Update the thank you message with custom HTML if (baseResult is ViewResult viewResult) { var formModel = viewResult.Model as FormViewModel; if (formModel != null) { // Pull the user's first name from the form fields var userName = viewModel.Fields["FirstName"]?.ToString() ?? "there"; formModel.ThankYouMessage = $@" <div class='dynamic-thank-you'> <h4>Hi <strong>{userName}</strong>!</h4> <p>Your submission has been received. Your reference ID is: <span class='ref-id'>{Guid.NewGuid().ToString().Substring(0, 8)}</span></p> </div>"; } } return baseResult; } - Compile your project, then find your custom form widget in Sitefinity’s widget library. Replace the default form widget with your custom one
- Test the form, and you’ll see a dynamic, HTML-styled thank you message tailored to the user’s submission
Quick Notes
- Don’t try to just paste HTML directly into the form’s default thank you message setting—Sitefinity will auto-filter out HTML tags for security
- Use custom CSS classes for your styling to avoid conflicts with Sitefinity’s default theme styles
- Double-check your HTML for validity to prevent layout issues
内容的提问来源于stack exchange,提问作者Tabish Usman
相关产品推荐
相关产品推荐

