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" />
<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!
Mark Bowen commented on
Feb 3,2010 at 2:25PM
David Henderson commented on
Feb 3,2010 at 2:34PM
Jeff Lleru commented on
Feb 3,2010 at 9:12PM
icebreaker commented on
Mar 23,2010 at 12:35AM
Matthew Thompson commented on
Apr 14,2010 at 9:22PM
Tim Jukes commented on
Jul 5,2010 at 7:12PM
danielle commented on
Jul 12,2010 at 4:02PM
Ty Wangsness commented on
Jul 12,2010 at 4:08PM
Stephen McIver commented on
Jul 13,2010 at 9:35AM
Ty Wangsness commented on
Jul 13,2010 at 9:57AM
dr3w commented on
Jul 16,2010 at 8:00PM
Chris Brauckmuller commented on
Jul 27,2010 at 11:01AM
Chris Brauckmuller commented on
Aug 11,2010 at 9:22AM
dr3w commented on
Aug 11,2010 at 9:31AM
Kyle commented on
Aug 26,2010 at 12:52PM
Chris Brauckmuller commented on
Aug 26,2010 at 12:53PM
Matt Crest commented on
Aug 26,2010 at 2:41PM
meredith commented on
Aug 27,2010 at 11:49AM
Ty Wangsness commented on
Aug 27,2010 at 11:54AM
dzr commented on
Aug 31,2010 at 9:40AM