ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

How to create success message without template

June 12, 2012 1:27am

Subscribe [2]
  • #1 / Jun 12, 2012 1:27am

    vw000

    482 posts

    I saw on a tutorial that you can show up a message without actually creating a template for it, for example after a form was submitted you can just create the url and its the same page but it shows the channel message after it.

    Can someone maybe refresh my mind?

  • #2 / Jun 12, 2012 6:09am

    John St-Amand

    865 posts

    You can just add a segment to the end of your URL that is the template’s cure to use one of the other.

    For example:

    {if segment_3 == "success"}
    
    This is where your success message would go.
    
    {if:else}
    
    This is where your form goes, and you would pass it a return URL that adds the "success" segment at segment 3.
    
    {/if}

    This assumes segment_3 is a segment that would not be there otherwise - it can be any segment - as long as it doesn’t match your template name, etc.

  • #3 / Jun 12, 2012 3:12pm

    vw000

    482 posts

    This would go in the template where the form is correct? Going to segment/success as url?

    This works on any form or just with EE forms. I just need to tell my form to which url to send the user on success. And I think its to overheat to duplicate the template form just to add the “Thank you” message on it.

  • #4 / Jun 12, 2012 3:16pm

    John St-Amand

    865 posts

    Yes, it would go in the template the houses the form.  And this should work in virtually any form or form add-on in EE that you use if it includes some form of return url parameter (as the native EE forms do - they may be called different things by some add-ons though).

    So it’s just a simple conditional that says “if the targeted segment is success, show the success message, if:else show the form”.

  • #5 / Jun 12, 2012 3:24pm

    vw000

    482 posts

    Thanks I will try it. I should be able to manually load the url segment in the browser as well to test the message correct? Like adding the “success” segment to the uri in the browser

  • #6 / Jun 12, 2012 3:25pm

    John St-Amand

    865 posts

    Yes, definitely.

  • #7 / Jun 12, 2012 3:29pm

    vw000

    482 posts

    Thank you that works and was very easy, just what I was looking for, instead of having to create a new template clone for each success message. As I have some forms based on different messages (depending on what users fills) this will save me from having allot of unnecessary files as all I need is to show a message.

    Im starting to like EE again after days of struggling with it. I guess there really is a learning curve into it. But I guess once you start to master it it can be quite powerful and flexible.

    Thank you John.

  • #8 / Jun 12, 2012 3:38pm

    John St-Amand

    865 posts

    No worries.  If you have a bunch of different success messages too - context specific stuff based on what they filled in, you can handle that with other conditionals (maybe a different segment at the end (you can disguise them a bit by using a digit or something instead of a word like “success”).  And once you throw in an early conditional parsing add-on like ifelse or switch (both from croxton on devotee.com) then you can do this without adding unnecessary hover head to your page.  Quick example, again assuming in this case that segment_3 is your “success” segment:

    {exp:switchee parse="inward" variable="segment_3"} 
    
    {case value="success1"}
    Success message for form result 1
    {/case}
    
    {case value="success2"}
    Success message for form result 2
    {/case}
    
    {case value="success3"}
    Success message for form result 3
    {/case}
    
    {case value=""}
    Display the form since success segment is blank
    {/case}
    
    {/exp:switchee}

    The above example uses switchee to do the conditional checking in place of using multiple if:else statements, which add weight to the page load.  Switchee matches the cases first then only parses the content between the case statement that is true.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases