SAEF edit form: how to make {custom_fields} supply the data
Posted: 08 March 2008 08:33 AM   [ Ignore ]  
Summer Student
Avatar
Total Posts:  24
Joined  11-12-2007

Hi,

I’m trying to use the {custom_fields} tags in an SAEF to edit an entry.

{exp:weblog:entries limit="1" weblog="specs_english"}
<table border='1'>
    <
tr>
        <
th>Edit:</th>
        <
th>{title}</th>
    </
tr>


        
{exp:weblog:entry_form weblog="specs_english" return="site/index" preview="site/entry" }
        
<input type='hidden' name='entry_id' value='{entry_id}'>
        
{custom_fields}
        
<tr>
            <
td>{field_label}{if required}* {/if}</td>
            <
td>
                
{if textarea}
                    
<textarea id="{field_name}" name="{field_name}" dir="{text_direction}" cols="50" rows="{rows}" onclick="setFieldName(this.name)">{field_data}</textarea>
                
{/if}
                {if textinput}
                    
<input type="text" dir="{text_direction}" id="{field_name}" name="{field_name}" value="{field_data}" maxlength="{maxlength}" size="50" onclick="setFieldName(this.name)" />
                
{/if}
                {if pulldown}
                    
<select id="{field_name}" name="{field_name}">
                        
{options}<option value="{option_value}"{selected}>{option_name}</option>{/options}
                    
</select>
                
{/if}
                {if date}
                    
<input type="text" id="{field_name}" name="{field_name}" value="{field_data}" maxlength="{maxlength}" size="50" onclick="setFieldName(this.name)" />
                
{/if}
                {if relationship}
                    
<select id="{field_name}" name="{field_name}">
                    
{options}<option value="{option_value}"{selected}>{option_name}</option>{/options}
                    
</select>
                
{/if}
            
</td>
        </
tr>
        
{/custom_fields}
        {
/exp:weblog:entry_form}

</table>
{/exp:weblog:entries}

(BTW - adding entries is done via the CP, not via this SAEF.)

My problem is: {field_data} is always empty.

Can anyone hit me with a cluestick to tell me what I am doing wrong? The entry’s title and id are generated okay.

Thanks a bunch… Nico

Profile
 
 
Posted: 09 March 2008 08:36 AM   [ Ignore ]   [ # 1 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  24513
Joined  05-20-2002

The SAEF isn’t technically meant for editing entries- thus the difficulties.  Have you checked out Solspace’s form helper?  It’s meant to aid with this- and is handy for ironing out the quirks you’ll run into.

I generally hard code the form when I need to edit it- and for dates, use the format:

value="{entry_date format='%Y-%m-%d %g:%i %A'}"

The date is stored in a different format than it’s displayed.  I suspect that’s the trouble you’re running into.

And I’m going to shift over to ‘How to’, since it’s a bit of a custom job to get an edit form working.  (Doable, though.)

 Signature 

AKA rob1

Help Request TipsPro Network

Profile
 
 
Posted: 09 March 2008 03:43 PM   [ Ignore ]   [ # 2 ]  
Summer Student
Avatar
Total Posts:  24
Joined  11-12-2007

Hi Robin,

Thanks for your reply. What a bummer, though. blank stare

Robin Sowell - 09 March 2008 08:36 AM

The SAEF isn’t technically meant for editing entries- thus the difficulties.

I can’t make out from the documentation that an SAEF is for adding entries only. It just states that I can “submit entries”.

Under “Custom Entry Fields” I see:

value="{field_data}"

To me, this indicates that the {custom_fields} tag can supply the data requested.

I will check out the form helper ASAP.

Robin Sowell - 09 March 2008 08:36 AM

The date is stored in a different format than it’s displayed.  I suspect that’s the trouble you’re running into.

That might be the trouble I will run into, but I did see how dates were stored in the database. Thanks for the warning though.

Bye… Nico

Profile
 
 
Posted: 10 March 2008 03:02 AM   [ Ignore ]   [ # 3 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  5931
Joined  11-23-2003

Though the SAEF may not be “technically meant” for editing, to say that it is widely used in such a way would be an understatement.  In fact, were the SAEF only be capable of editing it would be quite crippled.

The form helper is very useful but not required.  Actually, the most useful feature of the form helper is the README file and docs because both provide a template of what the “edit form” should look like.

Nico, as you have found, there are a couple of “gotcha’s” when using the SAEF for editing.  Without looking at my notes, here are the two you need to look for.

1. When using the SAEF to create an entry (new entry,) the entry ID is created on the submit.  When using the SAEF to edit an existing entry, the entry ID already exists and needs to be entered with an input field.

<input type="hidden" entry_id="" />

If you leave this out, then you will actually create a new entry rather than editing the old one.

2. As already mentioned, the date is the other gotcha.  When using the SAEF to create an entry you use the {entry_date} date as shown in the SAEF docs.  When using the SAEF to edit an existing entry, the date must be added in a specific format as shown by Robin (or in the helpful Form Helper docs.)

<input type="hidden" name="entry_date" value="{entry_date format='%Y-%m-%d %g:%i %A'}" />

I’m sure you guys already have this handled but I just wanted to add my 2 cents to help clarify some things.    By the way, Robin, thanks for the help.

 Signature 

WebmasterBasic: Rent a Webmaster | EE 2.0:  A designers dream becomes a developers dream | Follow me on Twitter.

Profile
 
 
Posted: 10 March 2008 03:26 AM   [ Ignore ]   [ # 4 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  5931
Joined  11-23-2003

Oh, and I think the problem that you are having regarding {field_data} being empty is that you are not actually viewing an entry.  The weblog fields tag should be filling the fields with data but you are saying all the fields are empty.  This is probably because either you are not using proper parameters to bring up an entry for the chosen weblog (entry could be expired for instance) or you are attempting to view an entry that does not exist for the weblog you are specifying.  If you are unsure, you might setup a basic template that would output the entry in question (without the SAEF stuff) to make sure you are using the correct parameters and other things I mentioned above.

 Signature 

WebmasterBasic: Rent a Webmaster | EE 2.0:  A designers dream becomes a developers dream | Follow me on Twitter.

Profile
 
 
Posted: 24 April 2009 08:21 AM   [ Ignore ]   [ # 5 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  335
Joined  12-08-2007

What were the results of this effort?  Success?

We have a similar need and it would be great to know that this is possible.

 Signature 

The opinions expressed in this post are not necessarily those of the author.

Profile
 
 
Posted: 24 April 2009 09:10 AM   [ Ignore ]   [ # 6 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  145
Joined  11-19-2008

Editing a stand alone entry form is definitely possible.

Biggest issue is {custom_fields} loop. I could never get that to work, so I hardcoded the fields… which you can do with an entry form as well. You provide field_id_# instead of field_name if you aren’t using Form Helper. I just recently was told about an interesting method using the {query} tag and perhaps that can work for this.

See Cem Meric’s example here:
http://expressionengine.com/forums/viewthread/110825/P54/

Form Helper is helpful. They recommend the following in their instructions (all of which are very important even if you aren’t using form helper although #1 may not be necessary if you can get that {query} to work):
“First Principals
1. To create a stand-alone edit form you will need to wrap the {exp:weblog:entries} tag inside the {exp:weblog:entry_form} tag. (Note that you can also wrap them in the reverse order.)

2. You will need to pass an entry_id to these tags whether in the URI or hard coded.

3. You will need to capture the entry_id as a value in a field of the form. The field can be hidden like this:
<input type=“hidden” name=“entry_id” value=”{entry_id}” />

4. You will need to capture the title as a value in a field of the form. The field can be hidden like this:
<input type=“hidden” name=“title” value=”{title}” />

5. You will need to capture the entry_date of the entry with a field something like this: (Note that the date formatting is critical.)
<input type=“hidden” name=“entry_date” value=”{entry_date format=’%Y-%m-%d %g:%i %A’}” />

6. You will need to capture the assigned categories of the entry using the field array method. This plugin contains a tag to help with this. (Note that the value of each field in the array must be the category id number.)
<input type=“hidden” name=“category[]” value=”{cat_id}” />”

Profile
 
 
Posted: 24 April 2009 09:45 AM   [ Ignore ]   [ # 7 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  335
Joined  12-08-2007

Shannon - Thanks so much for your keen insight and speedy reply. This is very helpful!

 Signature 

The opinions expressed in this post are not necessarily those of the author.

Profile
 
 
Posted: 24 April 2009 09:57 AM   [ Ignore ]   [ # 8 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  145
Joined  11-19-2008

No problem. Please let me know if that query method works. It could save a fair amount of time hard coding forms. It also likely fixes the gotcha listed in that thread with LG Tiny MCE… I’m thinking it might help someone use some of the other “special” fields out there in a saef… like the new data matrix fields.

I’ve gotten checkboxes to work in SAEF (edit and entry) as well (using php, but if I’d known about query, that might have worked there too!). As Cem Meric says, there is always another way… you just have to find it!

I’m hoping that 2.0 improves on the SAEF. It needs work!

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 77570 Total Logged-in Users: 38
Total Topics: 101561 Total Anonymous Users: 29
Total Replies: 544408 Total Guests: 227
Total Posts: 645969    
Members ( View Memberlist )
Newest Members:  tonybernardcarterstarksColeJLinskitnealsemperjrawhallshiusbozzlynobluffkatiejames