Form validation example?
Posted: 30 October 2010 05:20 PM   [ Ignore ]
Circled in the Yearbook
RankRankRank
Total Posts:  702
Joined  2010-04-08

Hi Rob, any chance of a simple form example using inline form validation and error messages please. I can’t get it to work and think an example would help me and other, get going.

Thanks a lot
Lee

[ Edited: 30 October 2010 05:44 PM by ifonly ]
Profile
 
 
Posted: 30 October 2010 08:38 PM   [ Ignore ]   [ # 1 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

Here’s an example. This is a completely dynamic form, getting the channel and entry from url segments.

<html>
    <
head>
        <
link href="{path=css/_ee_saef_css}" type="text/css" rel="stylesheet" media="screen" />
        
{exp:jquery:script_tag}
        {exp
:jquery:script_tag ui="datepicker"}
    
</head>
    <
body>
        
{exp:safecracker channel="{segment_2}" entry_id="{segment_3}" return="safecracker/{segment_2}/ENTRY_ID" error_handling="inline"}
            {if global_errors
:count}
            
<ul>
            
{global_errors}
                
<li>{error}</li>
            
{/global_errors}
            
</ul>
            
{/if}
            {if field_errors
:count}
            
<ul>
            
{field_errors}
                
<li>{error}</li>
            
{/field_errors}
            
</ul>
            
{/if}
            
<fieldset>
                <
label for="title">Title</label>
                <
input type="text" name="title" id="title" value="{title}" size="50" maxlength="100">
                
{if error:title}
                
<class="error">{error:title}</p>
                
{/if}
            
</fieldset>
            
            <
fieldset>
                <
label for="url_title">URL Title</label>
                <
input type="text" name="url_title" id="url_title" value="{url_title}" maxlength="75" size="50" />
                
{if error:url_title}
                
<class="error">{error:url_title}</p>
                
{/if}
            
</fieldset>
            
            
{custom_fields}
            
<fieldset>
                <
label for="{field_name}">{if required}{/if}{field_label}</label>
                
{if field_instructions}
                
<p>{field_instructions}</p>
                
{/if}
                {if error}
                
<class="error">{error}</p>
                
{/if}
                {formatting_buttons}
                {display_field}
            
</fieldset>
            
{/custom_fields}
            
            
<fieldset>
            
{status_menu}
                
<label for="status">Status</label>
                <
select name="status" id="status">
                    
{select_options}
                
</select>
            
{/status_menu}
            
</fieldset>
            
            <
fieldset>
                <
label for="entry_date">Date</label>
                <
input type="text" name="entry_date" id="entry_date" value="{entry_date}" maxlength="23" size="25" />
                
{if error:entry_date}
                
<class="error">{error:entry_date}</p>
                
{/if}
            
</fieldset>
                
            <
fieldset>
                <
label for="expiration_date">Expiration Date</label>
                <
input type="text" name="expiration_date" id="expiration_date" value="{expiration_date}" maxlength="23" size="25" />
                
{if error:expiration_date}
                
<class="error">{error:expiration_date}</p>
                
{/if}
            
</fieldset>
            
            <
fieldset>
                <
label for="comment_expiration_date">Comment Expiration Date</label>
                <
input type="text" name="comment_expiration_date" id="comment_expiration_date" value="{comment_expiration_date}" maxlength="23" size="25" />
                
{if error:comment_expiration_date}
                
<class="error">{error:comment_expiration_date}</p>
                
{/if}
            
</fieldset>
            
            <
fieldset>
                <
label class="checkbox"><input type="checkbox" name="sticky" value="y"  {sticky} /> Make Entry Sticky</label>
                <
label class="checkbox"><input type="checkbox" name="allow_comments" value="y" {allow_comments} /> Allow Comments</label>
                <
label class="checkbox"><input type="checkbox" name="dst_enabled" value="y" {dst_enabled} />DST Active on Date of Entry</label>
            </
fieldset>
            
            <
fieldset>
            
{category_menu}
                
<label for="categories">Categories</label>
                <
select name="category[]" id="categories" size="4" multiple="multiple">
                    
{select_options}
                
</select>
            
{/category_menu}
            
</fieldset>
            
            <
fieldset>
                <
input type="submit" value="Submit" />
            </
fieldset>
        
{/exp:safecracker}
    
</body>
</
html
Profile
 
 
Posted: 30 October 2010 09:07 PM   [ Ignore ]   [ # 2 ]
Circled in the Yearbook
RankRankRank
Total Posts:  702
Joined  2010-04-08

Perfect, thank you.

Profile
 
 
Posted: 30 October 2010 09:09 PM   [ Ignore ]   [ # 3 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

If you’re not using the custom fields loop, you can:

<fieldset>
    
{field:your_field_name}
    {if error
:your_field_name}
    
<class="error">{error:your_field_name}</p>
    
{/if}
</fieldset
Profile