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:

$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" />
    
    <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

say your piece

name

name

name

Remember my personal information

Notify me of follow-up comments?

Please enter the word you see in the image below: