Show Menu
Cheatography

Crownpeak Input Validation Cheat Sheet by

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 Projec­t\T­emp­lat­es­\Som­eTe­mpl­ateName

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 Projec­t\T­emp­lat­es­\Som­eTe­mpl­ateName

Example PostIn­put­Helper

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 Projec­t\L­ibrary

Example post_i­npu­t.aspx

PostInputHelper.RequiredField(asset, context, "page_title");
PostInputHelper.ValidEmail(asset, context, "email");
Place in Projec­t\T­emp­lat­es­\Som­eTe­mpl­ateName

Result

 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Crownpeak Input Controls Cheat Sheet
          Crownpeak Models Cheat Sheet
          Crownpeak Output.aspx Example Cheat Sheet

          More Cheat Sheets by GregFinzer

          Salesforce CLI Cheat Sheet
          Angular CLI Cheat Sheet
          Elasticsearch Example Queries Cheat Sheet