以下の内容はhttps://cheatography.com///gregfinzer/cheat-sheets/crownpeak-input-validation/より取得しました。


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

Related Cheat Sheets

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

More Cheat Sheets by GregFinzer

Loving Your Neighbor Cheat Sheet
AWS Core Service Options Cheat Sheet
Unity Container Cheat Sheet



以上の内容はhttps://cheatography.com///gregfinzer/cheat-sheets/crownpeak-input-validation/より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14