If no results conditionals
Posted: 01 December 2010 07:57 AM   [ Ignore ]
Wallflower
Rank
Total Posts:  14
Joined  2010-12-01

I’m using SC for editing entries. I’m calling in the entry id through segment_3.  If segment_3 doesn’t return entries, is there a way to show a message?  I’ve tried the following without success:

{if no_results}
        
<p>Put message here.</p>
        
{/if 
Profile
 
 
Posted: 01 December 2010 09:12 PM   [ Ignore ]   [ # 1 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

If you have the latest build, you can add

require_entry="yes" 

to your safecracker, and this will trigger the no_results block, making it an “edit-only” form.

Profile
 
 
Posted: 01 December 2010 10:33 PM   [ Ignore ]   [ # 2 ]
Wallflower
Rank
Total Posts:  14
Joined  2010-12-01

Hi Rob and thanks for the info.

What exactly is rendered on the page in the event an entry doesn’t exist?  Is there an error message?  I don’t want my users seeing a blank page if they’ve accidentally arrived at a URL with an invalid entry_id in the segment.

Profile
 
 
Posted: 01 December 2010 10:34 PM   [ Ignore ]   [ # 3 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

It’ll just show whatever’s in your no_results conditional.

Profile
 
 
Posted: 01 December 2010 10:36 PM   [ Ignore ]   [ # 4 ]
Wallflower
Rank
Total Posts:  14
Joined  2010-12-01

Ah, okay, so conditionals do work.  They just require the require_entry=“yes” parameter.  I missed that in your original answer.  Thanks so much!  I’ll test this asap.

Profile
 
 
Posted: 01 December 2010 10:40 PM   [ Ignore ]   [ # 5 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

Right, without the require_entry param, it assumes you want to add a new entry if there’s no valid entry specified.

Profile
 
 
Posted: 02 December 2010 05:03 AM   [ Ignore ]   [ # 6 ]
Wallflower
Rank
Total Posts:  14
Joined  2010-12-01

I’m still having trouble getting anything to render.  Blank screen.  Would you mind checking this fragment and telling me what’s wrong with it?

{exp:safecracker id="edit_profile" channel="golfers" return="signup/step3" preserve_checkboxes="yes" require_entry="yes" entry_id="{segment_3}" author_only="yes" safecracker_head="yes" datepicker="no" error_handling="inline"}
    
        
<input type="hidden" name="title" value="{title}" />
        <
input type="hidden" name="url_title" value="{url_title}" />
        
        
{custom_fields}        
        {if safecracker_file}
            {error
:g_photo}    
            
<p>
            <
label for="{field_name}">{field_label}:</label><br />
            
{display_field}
            
</p>
        
{/if}
        {
/custom_fields}
                
        
<p><input type="submit" value="Submit" class="submit" /></p>

        
{if no_results}
        
<p>Message goes here.</p>
        
{/if}

    {
/exp:safecracker} 

Thanks!

Profile
 
 
Posted: 02 December 2010 05:04 AM   [ Ignore ]   [ # 7 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

When you say blank screen, do you mean that nothing outside the safecracker tag prints out?

Profile
 
 
Posted: 02 December 2010 05:06 AM   [ Ignore ]   [ # 8 ]
Wallflower
Rank
Total Posts:  14
Joined  2010-12-01

No, everything else renders properly… just nothing from the SC loop.

Profile
 
 
Posted: 02 December 2010 05:12 AM   [ Ignore ]   [ # 9 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

Weird. Have you checked to see if you have the latest build? 110210

Profile
 
 
Posted: 02 December 2010 05:15 AM   [ Ignore ]   [ # 10 ]
Wallflower
Rank
Total Posts:  14
Joined  2010-12-01

Yes, I have Build 20101102.

Profile
 
 
Posted: 02 December 2010 05:38 AM   [ Ignore ]   [ # 11 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

Consider me stumped. Can you PM me a URL I can take a look at?

Profile
 
 
Posted: 02 December 2010 09:15 PM   [ Ignore ]   [ # 12 ]
Wallflower
Rank
Total Posts:  14
Joined  2010-12-01

Hey Rob.  I figured it out, and, of course, it was my fault.  I thought I was logged in, but wasn’t.  I need to set this page up to display a message when logged out.  Thanks for your time.

Profile
 
 
Posted: 02 December 2010 09:24 PM   [ Ignore ]   [ # 13 ]
Teen Scream
Avatar
RankRankRank
Total Posts:  3541
Joined  2009-05-29

Ah, that’s right, the form won’t display at all if you’re logged out.

Profile