How to Create Standalone Edit Forms in ExpressionEngine 2.0

Unfortunately in the latest version of EE 2.0 (2.0.1 Build 20100121 as of this writing) the SAEF core files are incapable of supporting edit functionality... this post will show you how to correct that shortcoming (and hopefully the core hack required here will be implemented in some future version of EE).

Standalone entry forms and standalone edit forms (ambiguously referred to as SAEF) have been of critical importance to many ExpressionEngine developers in the past. The {exp:weblog:entry_form} (renamed as {exp:channel:entry_form} in EE 2.0) is what allows us to let visitors to our sites create and edit entries without having access to the EE control panel... this has led to EE being capable of housing business directories, event calendars, and other types of sites with a focus on user-generated content.

First off, the core hack:

expressionengine/modules/channel/mod.channel_standalone.php, line 177 (edit: line 227 as of EE 2.1.0). You'll need to change the following line:

$success = $this->EE->api_channel_entries->submit_new_entry($channel_id, $data);

to this:

$success = isset($data['entry_id']) ? 
  $this->EE->api_channel_entries->update_entry($data['entry_id'], $data) :
  $this->EE->api_channel_entries->submit_new_entry($channel_id, $data);

For those familiar with coding edit forms in 1.6.x that'll get EE to behave as you're accustomed to. All the same required fields apply.

For those not familiar with the coding of an edit form or those who relied on the form_helper plugin, I'll show you how to get a very basic edit form working, based on the Agile Records default site.

First you'll need a template for this edit form, let's make a template group called "admin" with a template inside of it called "edit". Where you place your edit link is outside the scope of this post but if you've followed my template naming conventions you'll need to construct a link to this template for a particular entry like so:

<a href="{title_permalink="admin/edit"}">edit this entry</a>

The url should look something like: yourdomain.com/index.php/admin/edit/welcome_to_the_example_site

Now that we've gotten to the template we need to print the form fields and fill it with data from the entry. We'll use the {exp:channel:entries} tag to pull the data, but we'll make sure that the author is the current user just to make sure they're editing something they own. In an edit form you have to set the format values for each field as well as the entry_id (so that EE knows which entry you're trying to update). To have EE create the form with the necessary hidden fields we'll wrap all of this with the {exp:channel:entry_form} tag.

{exp:channel:entry_form channel="news" return="admin/index"}
  {exp:channel:entries channel="news" author_id="CURRENT_USER" status="Open|Closed" show_expired="yes" show_future_entries="yes" use_live_url="no"}
    <input type="hidden" name="entry_id" value="{entry_id}" />
    <input type="hidden" name="url_title" value="{url_title}" />
    <input type="hidden" name="field_ft_1" value="xhtml" />
    <input type="hidden" name="field_ft_2" value="xhtml" />
    <input type="hidden" name="field_ft_3" value="none" />
    {if status == "open"}<input type="hidden" name="status" value="{status}" />{/if}

    <div>
      <p>
        <b>News Title</b><br />
        <input type="text" name="title" id="title" value="{title}" size="50" />
      </p>
    </div>

    <div>
      <p>
        <b>News Body</b><br />
        <textarea type="text" name="field_id_1" cols="50" rows="10">{field_id_1}</textarea>
      </p>
    </div>

    <div>
      <p>
        <b>News Extended</b><br />
        <textarea name="field_id_2" cols="50" rows="10">{field_id_2}</textarea>
      </p>
    </div>

    <div>
      <p><input type="submit" value="Save Entry"></p>
    </div>
  {/exp:channel:entries}
{/exp:channel:entry_form}

As an aside, the reason I used {field_id_1} instead of {news_body} within the textarea is because that gets around the xhtml formatting on the field. Otherwise EE would wrap the content of that field in <p> tags which isn't what we want while editing.

Hopefully this helps some of you early EE 2.0 adopters. I realize this isn't a comprehensive guide to edit forms (I didn't talk about categories, file uploads, etc.) but I didn't want to overwhelm anyone just trying to get the basics to work. If you have questions or feedback please use the comments!


  • Hi Ty,

    Very very kind of you to post this for everyone to see. This is definitely a major issue at the moment with the forms not working the way they used to. I know the Edit form was never a sanctioned way of working but I’ve used it so many times and never had a problem with it so it’s good that this can still be done so thanks for sharing.

    Best wishes,

    Mark

    Mark Bowen commented on
    Feb 3,2010 at 2:25PM
  • Hi Ty,

    Great work, as you know this really pulled me out of a hole! Its good that this functionality can be returned in 2.0

    Thanks Again

    David

    David Henderson commented on
    Feb 3,2010 at 2:34PM
  • Thanks for posting that Ty! You are one sharp guy..

    Jeff Lleru commented on
    Feb 3,2010 at 9:12PM
  • Your post is the first one I have seen that offers clear instructions on how to build and use an edit form. Thanks!

    Would love to also have info on how you deal with related entries in an edit form.

    icebreaker commented on
    Mar 23,2010 at 12:35AM
  • Thanks for this info Ty.  Is there any possibility of you posting a followup to this to include how to deal with custom fields that are drop-down types or checkboxes?

    Matthew Thompson commented on
    Apr 14,2010 at 9:22PM
  • Saved my bacon! Thanks for posting this up - such a shame we need to hack the core to get EE2 to support this.

    Cheers
    Tim

    Tim Jukes commented on
    Jul 5,2010 at 7:12PM
  • I’m confused - being new to EE in general, trying to make the switch to EE2 and ran into the SAEF issue.

    What about just an add (not edit) form? How is that different from what’s being done here?

    thanks!

    danielle commented on
    Jul 12,2010 at 4:02PM
  • I’m hoping that the “maintenance” expressionengine.com is currently undergoing means that the release of EE 2.1 is imminent. There are quite a few SAEF bugs that should be fixed in that release.  Hopefully the hack documented here is also incorporated so that we don’t have to mess with our core files to enable edit forms.

    There are a number of issues that I don’t expect will be resolved, however. Most notably is that EE 2 SAEFs are currently incompatible with custom fieldtypes.

    At any rate, I’m hoping that I’ll be able to devote some time to writing a new guide to SAEFs after the launch of EE 2.1.  Hopefully enough has changed that will make the information contained in this post irrelevant. smile

    Ty Wangsness commented on
    Jul 12,2010 at 4:08PM
  • Didn’t see any mention of SAEF’s in the EE 2.1 changelog - hopefully this will be coming in the next build.

    Stephen McIver commented on
    Jul 13,2010 at 9:35AM
  • It appears that the 2.1 release still requires the core hack documented in this article. The line to change is now 227 of mod.channel_standalone.php.

    Ty Wangsness commented on
    Jul 13,2010 at 9:57AM
  • thanks for sharing…  beginning my new 2.1 install and this is a must.. lets see what happens!

    dr3w commented on
    Jul 16,2010 at 8:00PM
  • Thanks for this, it’s a huge help. I’m having no problem pulling in all my custom fields (text and textarea) to the edit form. However, when I go to submit, it doesn’t save them, just the title. Is there something special I have to do to accommodate custom fields to ensure they submit?

    Chris Brauckmuller commented on
    Jul 27,2010 at 11:01AM
  • Just an update, I’ve got image uploads and checkbox fields working too. If there’s demand for a tutorial, I’d be happy to write one.

    Chris Brauckmuller commented on
    Aug 11,2010 at 9:22AM
  • I think one can say “there is always a demmand”!!!  thanks!!

    dr3w commented on
    Aug 11,2010 at 9:31AM
  • Please create a tutorial for getting uploads and checkbox fields working! Pretty please!

    Kyle commented on
    Aug 26,2010 at 12:52PM
  • I’m actually working on it as we speak. Got the first draft done and working through revisions. Should be out soon, I’ll post when it is.

    Chris Brauckmuller commented on
    Aug 26,2010 at 12:53PM
  • Can’t wait for that Chris - thanks!

    (just wanting to be notified when Chris has the tutorial completed)

    Matt Crest commented on
    Aug 26,2010 at 2:41PM
  • I have my edit form working except for one thing - it’s saving as a new entry instead of an edit. Any ideas on how to fix that?

    I’m also awaiting a tutorial on implementing checkboxes in the saef. Thanks!

    meredith commented on
    Aug 27,2010 at 11:49AM
  • @meredith: my guess is you either don’t have the core hack in place or you’re not passing the existing {entry_id} as a hidden field in the edit form.

    Ty Wangsness commented on
    Aug 27,2010 at 11:54AM
  • Regarding the 2 hidden fields:
    <input type=“hidden” name=“field_ft_1” value=“xhtml” /> 
    <input type=“hidden” name=“field_ft_2” value=“xhtml” /> 
    <input type=“hidden” name=“field_ft_3” value=“none” /> 

    I get an Error on submit:
    Unknown column ‘field_ft_1’ in ‘field list’

    IF I remove field_ft_1 I get the same error for _2 and then _3.

    This is new - it was working fine and I’m not sure what I changed about the form to make this error occur. IF I remove all 3 fields the edit for works fine.


    QUESTION - can I leave these out? I’m not sure what these fields are doing…

    dzr commented on
    Aug 31,2010 at 9:40AM
  • Any hints on how to do multi-select/categories etc. so that the values are selected?

    thanks

    danielle commented on
    Sep 14,2010 at 9:48AM
  • Thanks for sharing this workaround Ty.. it’s a bit puzzling that the official EE2 doesn’t (yet?) incorporate such a simple addition, which enables a very useful functionality.

    Matteo commented on
    Sep 30,2010 at 7:33AM
  • Hey - anyone doing SAEF in EE2 - check out this add-on: SafeCracker http://barrettnewton.com/products/safecracker/

    It takes care of the fact that EE2 doesn’t support Playa in stand alone forms. It’s also pretty rad for other stuff.

    danielle commented on
    Sep 30,2010 at 8:08AM
  • Thanks for this posting.
    Is the tutorial ready Chris? or can you sent only the code? I use solspace tag for 2.1. Is this field also editable? or must I switch to PHP outside EE.

    Marcus commented on
    Nov 28,2010 at 2:19AM
  • Thank you for sharing this codes.
    Try this game out design home app

    Alex Jacob commented on
    Mar 25,2019 at 8:03AM
  • Thank you for the help.  I’ve trying to figure out the code on my business site for a few hours now.

    Henry
    IT - Columbia Tree Service

    Henry Reed commented on
    Apr 16,2019 at 9:28AM
  • Thanks for your post! Are you really sure about what you say? I read something different on an other blog! I’ll share the link. Event Planner Orlando

    Joshua A. Price commented on
    Apr 29,2019 at 11:49PM
  • This is a good information given by yours, I’ll keep on track to this article for new updates and news. Thank you so much!
    Cincinnati Sign Company

    Meggy commented on
    May 22,2019 at 10:58AM
  • Thanks for creating this. I really feel as though I know so much more about the topic than I did before. You should continue this, I’m sure most people would agree you’ve got a gift.  our site

    casseverhart13 commented on
    Jun 13,2019 at 12:09AM
  • Toda la información que necesitas sobre la harina de avena de sabores. Solamente en el siguente enlace.

    Mihai P. commented on
    Jun 13,2019 at 7:49AM
  •   montre komono   «HAPPY»

    montre komono commented on
    Jul 4,2019 at 10:06AM
  • chromecast setup is the excellent-value video streaming dongle by Google that can turn any dumb TV into a Smart one

    setup chromecast commented on
    Sep 3,2019 at 7:53AM
  • this is a great submission

    great form commented on
    Oct 14,2019 at 2:15AM
  • This is nice. I think I may need your help.
    Michael | california llc

    Michael Smith commented on
    Oct 14,2019 at 7:53AM
  • Thanks for this tutorial! I cant thank you enough.
    Michael | www.rosevillewaterheater.com/

    Michael Smith commented on
    Oct 14,2019 at 12:28PM
  • Thanks for sharing this workaround Ty.. it’s a bit puzzling that the official EE2 doesn’t (yet?) incorporate such a simple addition, which enables a very useful functionality.https://www.brillianceremovalistsmelbourne.com.au/

    Morris commented on
    Oct 31,2019 at 9:14AM
  • Thanks for sharing this workaround Ty.. it’s a bit puzzling that the official EE2 doesn’t (yet?) incorporate such a simple addition, which enables a very useful functionality.https://www.brillianceremovalistsmelbourne.com.au/

    Morris commented on
    Oct 31,2019 at 9:22AM
  • Pretty sweet code will come in handy for my mobile mechanic site.

    Joe Momma commented on
    Nov 2,2019 at 7:51PM
  • Finally!! It’s time to create that madass!! Form

    Learn How-to do it yourself on HowTo9ja

    Howto9ja commented on
    Nov 2,2019 at 8:22PM
  • it actually finally worked here. thanks ! swimming pool maintaining

    ritz commented on
    Nov 3,2019 at 7:08AM
  • Great coding. Thanks bro! Swiftbonds

    Swiftbonds commented on
    Nov 3,2019 at 10:20PM
  • Is there any possibility of you posting a followup to this to include how to deal with fields that are drop-down types or checkboxes? Thats something my seo agency and i would appreciate! idaho falls seo specializes in idaho falls seo and idaho falls seo and web design

    Victor commented on
    Nov 4,2019 at 8:07PM
  • All good with the edit form except it’s coming in as a new entry. I’m a software engineer and running into a bit of a wall. Any ideas on how to fix that?

    Thanks!

    Electrifying Design LLC commented on
    Nov 6,2019 at 12:30AM
  • Thanks for your great post.
    If you’re interested in grooming your dogs,
    Just click here and take a look.

    Nick commented on
    Nov 11,2019 at 11:21PM
  • The embedded value on the following is hard to separate within the limits.
    div>
    11
       
    12
          News Title

    13
          <input type=“text” name=“title” id=“title” value=”{title}” size=“50” />
    14
       
    15
      </div>
    16
    17
      <div>
    18
        electrician noosa

    19
          News Body

    20
          <textarea type=“text” name=“field_id_1” cols=“50” rows=“10”>{field_id_1}</textarea>
    21
       

    Paul Harvey commented on
    Nov 12,2019 at 3:12AM
  • diagnostic-immobilier-13009.fr

    diagnostic-immobilier-13009.fr commented on
    Nov 12,2019 at 6:25AM
  • Thanks so much for this article! This is really helpful for us. spray foam insulation okc

    Mazikeen commented on
    Nov 15,2019 at 7:23AM
  • Just when i thought EE 2.0 does not support anymore the functionality, Thanks for this important update.arborists canberra

    Morris commented on
    Nov 18,2019 at 6:21PM
  • Thanks for sharing this great information.
    Bruno from elagage

    Bruno commented on
    Nov 28,2019 at 4:14PM
  • I’m so happy having these codes. Thanks for your knowledge!
    | Social Security Card Application

    Dan commented on
    Nov 29,2019 at 9:53AM
  • Great ideas and discussion! Keep it up. Thanks | Gucci Bag

    Meg commented on
    Nov 29,2019 at 10:01AM
  • I am in agreement with the others on how wonderful this post is.

    Jessie | <a >​Concrete in Chicago</a> |
    <a >basement waterproofing rockford il</a>

    Jessie R commented on
    Dec 7,2019 at 7:47PM
  • diageco13.fr

    diageco13.fr commented on
    Dec 9,2019 at 9:52AM
Commenting is not available in this weblog entry.