Cheatography
https://cheatography.com
Input Validation for Crownpeak
Example input.aspx
Input.ShowHeader("Contact Us");
Input.ShowTextBox("Page Title", "page_title");
Input.ShowWysiwyg("Address", "address", ServicesInput.FullWYSIWYG());
Input.ShowTextBox("Customer Service Phone", "customer_service_phone");
Input.ShowTextBox("Email", "email");
|
Place in Project\Templates\SomeTemplateName
Example output.aspx
<h1><%= asset["page_title"] %></h1>
<p><%= asset["address"] %></p>
<p><%= asset["customer_service_phone"] %></p>
<p><a href='mailto:<%= asset["email"] %>'><%= asset["email"] %></a></p>
|
Place in Project\Templates\SomeTemplateName
Example PostInputHelper
using System.Text.RegularExpressions;
using CrownPeak.CMSAPI;
/ Some Namespaces are not allowed. /
namespace Developer_Training.Project.Library
{
public static class PostInputHelper
{
public static bool RequiredField(Asset asset, PostInputContext context, string field)
{
bool isValid = true;
if (!context.InputForm.HasField(field))
{
context.ValidationErrorFields.Add(field, "This is a required field");
isValid = false;
}
else if (!asset.Label.Equals(context.InputForm[field]))
{
asset.Rename(context.InputForm[field]);
}
return isValid;
}
public static bool ValidEmail(Asset asset, PostInputContext context, string field)
{
bool isValid = true;
if (!Regex.IsMatch(context.InputForm[field], @"[@\s]+@[@\s]+\.[@\s]+$"))
{
context.ValidationErrorFields.Add(field, "Please enter a valid email address");
isValid = false;
}
else if (!asset.Label.Equals(context.InputForm[field]))
{
asset.Rename(context.InputForm[field]);
}
return isValid;
}
}
}
|
Place in Project\Library
Example post_input.aspx
PostInputHelper.RequiredField(asset, context, "page_title");
PostInputHelper.ValidEmail(asset, context, "email");
|
Place in Project\Templates\SomeTemplateName
|
Created By
www.kellermansoftware.com
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets
More Cheat Sheets by GregFinzer