Problems, need help? Have a tip or advice? Post it here.
7 posts Page 1 of 1
Wanted to pick some brains here as I am in a bit of a problem.

Form submit data using db_persist to form.php template.
During this process, I set two sessions
I redirect to the thank you page
Thank you page shows a receipt, I thought to use the email and invoice # as sessions to pull the data on the thank you page. I thought it would work, but it doesn't. At least... The first time. :)

Code: Select all
<cms:pages masterpage="form.php" custom_field="email==<?php echo $_SESSION['email']; ?> | invoice==<?php echo $_SESSION[last-invoice']; ?>" limit="1" >


The page redirects and nothing is there. I hit refresh and data is there. I am thinking it is redirecting to quick before the data is processed and saved by couch? If so is there a way to stall the redirect a second or two? I am using:

Code: Select all
<cms:redirect url="<cms:link masterpage='donate.php' page='thank-you' />" />


To go back to the thank you page.

Is there another way to handle this? Handling thank you pages where we can pull data saved for that user and display it all within couch?

Thanks!
Is there another way to handle this? Handling thank you pages where we can pull data saved for that user and display it all within couch?

You don't have to resort to php to pass this information to your thank you page. Couch has some built in tags for handling sessions. Use cms:set_flash to send the variables and cms:get_flash to receive them.

This is an example from a contact form that includes the following flash cookies and a redirect as part of the success condition.
Code: Select all
        <cms:set_flash name='message' value=frm_message/>
        <cms:set_flash name='realname' value=frm_realname/>
        <cms:redirect url="<cms:link masterpage='contact-thanks.php'/>"/>

The contact-thanks.php page then repeats their message back to the user.
Code: Select all
<h1>Thank you<cms:if "<cms:not_empty "<cms:get_flash 'realname'/>" />" >, <cms:get_flash 'realname'/></cms:if>! Your message has been sent.</h1>
<p class="center">We will respond by email as soon as we can.</p>
                               
<cms:if "<cms:not_empty "<cms:get_flash 'message'/>" />" ><p>Your message: <cms:get_flash 'message'/></p></cms:if>

Something similar should work for your case.

The set_flash and get_flash tags are discussed in the DBF Tutorial, and need to be activated in your addons folder.
http://docs.couchcms.com/concepts/databound-forms.html

P.S. The code above is a little obfuscated by the cms:if conditions included. I added those because if you refresh the page, the cookies are gone. The message looks weird if it's incomplete. cms:set_cookie creates a more persistent cookie.
On the other hand, if the problem is that you get to the thank you page before your processing script puts the information into the database, you could create a delay by first sending the user to an intermediate thank you page with a "click for a receipt" button.

Another possibility would be to use some sort of timer, for instance using the php sleep() function to create a delay.

I'm not convinced though that a simple delay would be reliable enough. Doesn't the card processor provide some sort of API or script specifically for this very purpose?
@John, @Tim,
The problem is not that the redirect happens too soon and the data is not persisted by then.

The following thread will explain the actual cause (and also the solution) -
https://www.couchcms.com/forum/viewtopi ... 579#p19579

Hope it helps.
Tim, thanks for your words! I switched to get_flash but I am glad I waited for KK to respond. I was about to put a button that opens a Modal window for the receipt but I really didn't want to. That one addition to the cms:pages did the trick perfectly, thank you everyone!
Hi Tim or KK,

On the code below is there a way to make it so the flash lasts longer? A session would normally last until the user closes their browser.

When I use set_flash and then get_flash it works great the first time, but it get lost after.

Thanks

tim wrote:
Is there another way to handle this? Handling thank you pages where we can pull data saved for that user and display it all within couch?

You don't have to resort to php to pass this information to your thank you page. Couch has some built in tags for handling sessions. Use cms:set_flash to send the variables and cms:get_flash to receive them.

This is an example from a contact form that includes the following flash cookies and a redirect as part of the success condition.
Code: Select all
        <cms:set_flash name='message' value=frm_message/>
        <cms:set_flash name='realname' value=frm_realname/>
        <cms:redirect url="<cms:link masterpage='contact-thanks.php'/>"/>

The contact-thanks.php page then repeats their message back to the user.
Code: Select all
<h1>Thank you<cms:if "<cms:not_empty "<cms:get_flash 'realname'/>" />" >, <cms:get_flash 'realname'/></cms:if>! Your message has been sent.</h1>
<p class="center">We will respond by email as soon as we can.</p>
                               
<cms:if "<cms:not_empty "<cms:get_flash 'message'/>" />" ><p>Your message: <cms:get_flash 'message'/></p></cms:if>

Something similar should work for your case.

The set_flash and get_flash tags are discussed in the DBF Tutorial, and need to be activated in your addons folder.
http://docs.couchcms.com/concepts/databound-forms.html

P.S. The code above is a little obfuscated by the cms:if conditions included. I added those because if you refresh the page, the cookies are gone. The message looks weird if it's incomplete. cms:set_cookie creates a more persistent cookie.
Use cms:set_cookie and cms:get_cookie for a longer lasting cookie. You can set an expiration time in seconds, but the default is to expire at the end of the session.

http://docs.couchcms.com/tags-reference/set_cookie.html
7 posts Page 1 of 1