ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Safecracker and if:else issue

April 26, 2012 2:48pm

Subscribe [1]
  • #1 / Apr 26, 2012 2:48pm

    Mindvolt

    14 posts

    I have a template called post.html in group.group. The template includes a safecracker form. I have the safecracker form inside and if/else statement so that if the url is /group/post/title then the safecracker form loads an existing entry for editing. If there is no title segment (url is only /group/post) then it loads a blank safecracker form to create a new post. Here’s my code:

    {if segment_3 != ""}
              {exp:safecracker channel="trophy_gallery" return="community/post/gallery/success" class="clearfix" safecracker_head="yes" include_jquery="no" datepicker="no" error_handling="inline" require_entry="yes" url_title="{segment_3}" author_only="yes"}
    
                    // edit entry form code
    
                {/exp:safecracker}
    {if:else}
                {exp:safecracker channel="trophy_gallery" return="community/post/gallery/success" class="clearfix" safecracker_head="yes" include_jquery="no" datepicker="no" error_handling="inline" require_entry="no" author_only="no"}
    
                   // create entry form code
                
                {/exp:safecracker}
    {/if}

    For some reason the safecracker settings like require_entry, url_title and author_only are effecting the safecracker setup in the “else” block of the code. So when I load a url without a third segment it’s telling me no entry was provided.

    Is there something wrong with the way I’m formatting this (a better way to do so), or is this potentially a bug in how the safecracker tags are being parsed?

  • #2 / Apr 27, 2012 12:40pm

    Mindvolt

    14 posts

    Any ideas about this one? I’d like get this resolved, hopefully without adding additional templates or url segments.

  • #3 / Apr 27, 2012 2:52pm

    Dan Decker

    7338 posts

    Hi Mindvolt,

    Thanks for your question!

    There is no need for the {if} statement, SafeCracker does this on its own. If you do not supply any identifying info, like an entry_id or url_title, SafeCracker automatically creates a new entry.

    Try this:

    {exp:safecracker channel="trophy_gallery" return="community/post/gallery/success" class="clearfix" safecracker_head="yes" include_jquery="no" datepicker="no" error_handling="inline" url_title="{segment_3}" entry_id="" author_only="yes"}
                    // edit entry form code
    {/exp:safecracker}

    Note the empty entry_id parameter. With entry_id and url_title both empty, which would happen if {segment_3} were empty, SafeCracker creates a new entry.

    Let me know if you have any questions.

    Cheers,

  • #4 / Apr 27, 2012 3:56pm

    Mindvolt

    14 posts

    Ah ha, that makes perfect sense. Not sure why I didn’t think to try it that way at the first!

    Thanks Dan.

  • #5 / Apr 30, 2012 4:48pm

    Dan Decker

    7338 posts

    Hi Mindvolt,

    No worries!

    Is there anything else I can assist you with?

    Cheers,

  • #6 / Apr 30, 2012 4:52pm

    Mindvolt

    14 posts

    Nope that covers it. Thanks.

  • #7 / May 01, 2012 2:38pm

    Dan Decker

    7338 posts

    Hi Mindvolt,

    Awesome.

    If you need anything in the future, just lest us know!

    Cheers,

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases