1

I've come across this problems enough times now that I'm curious if anyone has sort of a best practice for it that might be helpful.

I have a channel form page that needs to know if the user has already started the application, and there for allow them to edit it, or if if they haven't create a new one.

A simple enough problem it would seem but one I'm constantly tripped up on

Using Stash I've come up with something that "kindof" works but not really

Basically at the top of the page i look for an existing application by that author, something like this

{exp:stash:set name="app_id" parse_tags="yes" type = "snippet"}
{exp:channel:entries channel="applications" author_id="{logged_in_member_id}" limit="1" status="not Closed"}
   {entry_id}
{/exp:channel:entries}
{/exp:stash:set}

Which will get the entry id of an application if there is one, and return nothing if there isnt.

then for the application itself do something like this

{if {exp:stash:not_empty name="app_id"}}
 {exp:channel:form channel="applications" entry_id="{app_id}" return="step2" }
...
  {/exp:channel:form}
{if:else}
   {exp:channel:form channel="applications" return="step2" }
    ...
   {/exp:channel:form}
{/if}

Currently there are two issues:

  1. i can get the app_id to render in the page but parse order seems to be an issue as the channel form tag is parsing first and gets an "invalid entry" error, even if its a simple conditional, its always returning false?

    {if {exp:stash:not_empty name="app_id"}}{/if}

  2. This method means i have to maintain two copies of the form and just feels messy?

Is there an easier way to do this?

1
  • If you pass entry_id="" or entry_id="0" to your form, does it work as if entry_id param was not present? Nov 7, 2013 at 10:01

3 Answers 3

2

One option would be to continue with setting the Stash app_id variable like you are and then embed the form (either Stash embed or EE), then use the app_id variable in the channel:form parameters in the embed. That keeps you from duplicate forms.

Another option would depend on your url setup, but you could redirect to the current form page with the found entry id as an additional url segment. Something like:

{exp:channel:entries channel="CHANNEL" author_id="{logged_in_member_id}" limit="1" status="not Closed" dynamic="no"}
    {if segment_3 == "" AND entry_id != ""}{redirect="TEMPLATE_GROUP/TEMPLATE/{entry_id}"}{/if}
{/exp:channel:entries}

{exp:channel:form 
    channel="CHANNEL" 
    entry_id="{segment_3}"
    author_only="yes"
    return="TEMPLATE_GROUP/TEMPLATE/ENTRY_ID/success" 
}
     etc….
1

Think I might be missing something regarding the maintaining of two copies of the form but as for the parsing issue. If the channel:form tag is parsing first and you need it to parse it after why not put it in an embeded template call. embeded templates are parsed after the rest of the regular template.

0

I had a similar issue with the following code:

{exp:channel:form 
 channel="CHANNEL" 
 entry_id="{exp:stash:b_entry_id}" 
}

Simply adding parse="inward" to the {exp:channel:form} tag sorted it all out. so now I have:

{exp:channel:form 
 channel="CHANNEL" 
 entry_id="{exp:stash:b_entry_id}" 
 parse="inward"
}

The idea came from this post by Mark Croxton on the Stash support forum.

If you want to know more about parsing order, or parse="inward" check out the EE Docs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.