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 edit entries form?

April 23, 2012 3:47pm

Subscribe [2]
  • #1 / Apr 23, 2012 3:47pm

    apiwebservices

    15 posts

    So I have a SafeCracker form that lets members create a classified ad entry. That form works fine. Now how do I build the ‘edit entry’ form? There are no examples of this on the User Guide.

    This is the “list entries” page, where I have listed each member’s open ads:

    {embed="inc/begin_head" entry_title="Edit Classified Ad"}
    {embed="inc/end_head"}
    {embed="inc/limited_sidebar"}
    {embed="membership/menu"}
    <h2>Edit My Classified Ad</h2>
    <p>{if logged_out}<br />
    <a href="http://{path=">Log in</a> to edit your entries.<br />
    {/if}<br />
    {if logged_in}<br />
    {exp:safecracker channel="classifieds" return="/classifieds/edit/ENTRY_ID" author_only="yes" error_handling="inline" entry_id="{segment_3}"}<br />
    <li><a href="http://{path=classifieds/edit}/{entry_id}">Edit - {title}</a></li><br />
    {/exp:safecracker}<br />
    {/if}<br />
    {embed="inc/footer"}

    This is the form to post a classified entry:

    {embed="inc/begin_head" entry_title="Place Classified Ad"}
    {embed="inc/end_head"}
    {embed="inc/limited_sidebar"}
    {embed="membership/menu"}
    <h2>Place Classified Ad</h2>
    <p>{if logged_in}<br />
    {exp:safecracker channel="classifieds" return="/classifieds/edit/ENTRY_ID" author_only="yes" error_handling="inline" class="safecracker"} <br />
     All listings expire in 30 days.<br />
     <label class="reverse" for="form-title">Title</label></p>
    
    <p>  <input id="form-title" name="title" type="text" size="75" value="{title}" /></p><br />
    {custom_fields}<br />
    {field_errors}{error}{/field_errors}<br />
    {if wygwam}<br />
       {display_field}<br />
    {/if}<br />
    {if matrix}<br />
       {display_field}<br />
    {/if}<br />
    {if textarea}<br />
    <label class="reverse" for="{field_name}">{field_label}</label></p>
    
    <p><textarea id="{field_name}" name="{field_name}" dir="{text_direction}" cols="50" rows="{rows}">{field_data}</textarea></p><br />
    {/if}<br />
    {if textinput}<br />
    <input type="text" dir="{text_direction}" id="{field_name}" name="{field_name}" value="{field_data}" maxlength="{maxlength}" size="50" /></p><br />
    {/if}<br />
    {if date}<br />
    <input type="text" id="{field_name}" name="{field_name}" value="{field_data}" maxlength="{maxlength}" size="50" /><br ><br />
    {/if}<br />
    {if file}<br />
     {display_field}<br />
    {/if}<br />
    {/custom_fields}  <br />
     <input type="submit" value="Submit" /></p> <br />
    {/exp:safecracker}<br />
    {if:else} You are not logged in. Please <a href="http://{path=">log in</a>.{/if}<br />
    {embed="inc/footer"}

  • #2 / Apr 24, 2012 12:16pm

    Dan Decker

    7338 posts

    Hi apiwebservices,

    Thanks for your question about SafeCracker!

    Indeed, it is not entirely clear, but if you supply your entry form with either a url_title or entry_id, it magically becomes an edit form.

    You would need a way to link to your form for editing, so from your member’s ad listing, something like this:

    <a href="http://{entry_id_path=’template-group/template’}">Edit your Ad!</a>

    That path variable will supply the ad entry’s ID to your SafeCracker template and present the entry for editing.

    Let me know if you have any questions or run into any snags.

    Cheers,

  • #3 / Apr 24, 2012 3:37pm

    apiwebservices

    15 posts

    This ad should show up, but it’s not. The “Edit my ad!” link from the displayed ad works fine. It grabs the ENTRY_ID number and then redirects. But now the edit page has empty form fields—none of my information displays.

    {embed="inc/begin_head" entry_title="Edit Classified Ad"}
    {embed="inc/end_head"}
    {embed="inc/limited_sidebar"}
    {embed="membership/menu"}
    <h2>Edit Classified Ad</h2>
    <p>{if logged_in}<br />
    {exp:safecracker channel="classifieds" return="/classifieds/full-view" author_only="yes" error_handling="inline" class="safecracker"}<br />
     <label class="reverse" for="form-title">Title</label></p>
    
    <p>  <input id="form-title" name="title" type="text" size="75" value="{title}" /></p><br />
    <div class="reverse"><br />
    {custom_fields}<br />
    {field_errors}{error}{/field_errors}<br />
    {if wygwam}<br />
       {display_field}<br />
    {/if}<br />
    {if matrix}<br />
       {display_field}<br />
    {/if}<br />
    {/custom_fields} <br />
    </div> <br />
     <input type="submit" value="Submit" /></p> <br />
    {/exp:safecracker}<br />
    {if:else} You are not logged in. Please <a href="http://{path=membership/}">log in</a>.{/if}<br />
    {embed="inc/footer"}

  • #4 / Apr 25, 2012 5:05pm

    Dan Decker

    7338 posts

    Hi apiwebservices,


    I haven’t used Wygwam in a SafeCracker before, but this should work:

    {if wygwam}
       <textarea id="{field_name}" name="{field_name}" dir="{text_direction}" rows="{rows}">{field_data}</textarea>
    {/if}

    Matrix is even more tricky, but it evan be done. There are some examples in the Pixel & Tonic support areas.

    Cheers,

  • #5 / Apr 25, 2012 5:09pm

    apiwebservices

    15 posts

    I noticed I was also missing

    entry_id="{segment_3}"

    in the safecracker channel. Works like a charm now. Thank you!

  • #6 / Apr 26, 2012 4:15pm

    Dan Decker

    7338 posts

    Hi apiwebservices,

    Good to hear!

    If you need anything else, just let us know.

    Cheers!

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

ExpressionEngine News!

#eecms, #events, #releases