Forum for discussing general topics related to Couch.
3 posts Page 1 of 1
Hi,
I have tried to find information in the documentation but I can't seem to find a way to achieve this.

Basically I have a form on one page (2 fields: name and email). On successful submission I would like those 2 variables stored so on redirect to another page I can output those variables.

Is this possible?

Thanks.
Hi,

HTTP being a stateless protocol, values of variables set on one page are not retained by default as the visitor moves on to another page.

To persist values between pages, additional effort is required.
Usually one of the following methods are used -
1. Passing values in cookies
2. Passing values as querystring parameter (GET)
3. Passing values as POST variables
4. Using session variables
5. Persisting in database.

For the purpose that you mentioned, the most straightforward to implement would be the second method mentioned above - passing values as querystring variables.

Here is a sample code (we assume that 'first.php' is the page that has the form in it and 'second.php' is the page that we redirect to after successful form submission and display the submitted values)
First.php
Code: Select all
<cms:form method="post">
   <cms:if k_success >
      <cms:redirect "second.php?name=<cms:show frm_name />&mail=<cms:show frm_email />" />
   </cms:if>
   
   <cms:if k_error >
      <h3>Failed to submit form</h3>
      <cms:each k_error >
         <cms:show item /><br>
      </cms:each>
   </cms:if>
   
   Your Name: <cms:input type="text" size="10" name="name" required='1' /><br />
   Your Email: <cms:input type="text" size="10" name="email" required='1' validator='email' /><br />

   <cms:input name="submit" type="submit" value="Send" />
</cms:form>

Second.php

Code: Select all
<cms:set param1="<cms:gpc 'name' method='get' />" /> 
<cms:set param2="<cms:gpc 'mail' method='get' />" />   

<cms:if param1 && param2>
   You inputted name: <cms:show param1 /> and mail: <cms:show param2 />
</cms:if>

Notice how we use cms:gpc tag to retrieve the values from the querystring.

Hope this helps.
Thanks again for the quick reply.
This looks perfect, I will give it go.
3 posts Page 1 of 1
cron