Problems, need help? Have a tip or advice? Post it here.
7 posts Page 1 of 1
Hi,
Is there any way to clear the contact form after submission. Currently the form fields hold their values after clicking submit. My code is below.

Code: Select all
<cms:form action='' method='post' id='contact_form'>
                  <label for="name">Name</label>
                  <cms:input type='text' name='name' id='name' required='1' class="span5" />
                  <cms:if k_error_name>
                     <p id='name_error' class='help'>Insert a Name</p>
                  </cms:if>
   
                  <label for="email">Email Address</label>
                  <cms:input type='text' name='email' id='email' required='1' validator='email' class="span5" />
                  <cms:if k_error_email>
                     <p id='email_error' class='help'>Enter a valid email address</p>
                  </cms:if>
   
                  <label for="subject">Subject</label>
                  <cms:input type='text' name='subject' id='subject' required='1' class="span5" />
                  <cms:if k_error_subject>
                     <p id='subject_error' class='help'>Enter a message subject</p>
                  </cms:if>
   
                  <label for="message">Message</label>
                  <cms:input type='textarea' name='message' id='message' required='1' rows='6' class="span5"></cms:input>
                  <cms:if k_error_message>
                     <p id='message_error' class='help'>Enter a message</p>
                  </cms:if>
               
               <cms:if k_success >   
                  <p id='mail_success' class='success'>Thank you. We will get back to you as soon as possible.</p>
                  
                  <cms:send_mail from=k_email_from to=k_email_to subject='Feedback from your site'>
                     The following is an email sent by a visitor to your site :
                     <cms:show k_success />
                  </cms:send_mail>
               </cms:if>
               <div class="clearfix"></div>
               <input type='submit' id='send_message' class="btn" value='Submit' />
               </cms:form> 
Hi,

The cleanest way to do so would be to redirect back to the same page after successful form submission (thus reloading a fresh and blank form).
Code: Select all
<cms:if k_success >
    <cms:redirect k_page_link />   
</cms:if>

However, by simply redirecting we won't be able to show the success message to the user.
To handle just this kind of scenario v1.3.5 of Couch (downloadable currently from viewtopic.php?f=5&t=7377) has the new 'get_flash' and 'set_flash' tags. These tags can set variables (like our success message) that lasts for only the next reload of the page.

If you can upgrade to 1.3.5, the following changes would do the trick (I am showing only the modified parts of the code) -
Code: Select all
<cms:if "<cms:get_flash 'success_msg' />" >
    <p id='mail_success' class='success'><cms:get_flash 'success_msg' /></p>
</cms:if>

<cms:form action='' method='post' id='contact_form'>
    ...
    <cms:if k_success >   
        <cms:send_mail from=k_email_from to=k_email_to subject='Feedback from your site'>
            The following is an email sent by a visitor to your site :
            <cms:show k_success />
        </cms:send_mail>
       
        <cms:set_flash name='success_msg' value="Thank you. We will get back to you as soon as possible." />
        <cms:redirect k_page_link />
    </cms:if>
    ..
</cms:form>

Notice how we set the success message, then redirect. Upon reload, we check for any success message before the form itself.

Hope this helps.
I upgraded but it is not recognizing the get_flash tag so probably something wrong with my upgrade. I will try upgrading again. Thanks for the help.
I am so sorry - it is stated in the docs but I really should have mentioned that the new functionality is contained in an addon and hence will need to be enabled before using it -
In the 'couch/addons' folder you'll find a file named 'kfunctions.php'. Use your text editor to edit the following line and remove the leading double-slashes ('//').
Code: Select all
//require_once( K_COUCH_DIR.'addons/cart/session.php' );

Once enabled, the new session tags will become available.
Hope this helps. Please let me know.
Thanks.
Hi, yes this worked. Thanks for the reply & the contact form code. Great customer support.
Our first Couch CMS based site is now live and we look forward to using this platform again.
Thanks
Hi,

Is there a way to display a success message after form submit, on a custom page like submit-success.php in a different manner, not linked to the form itself?

I'm asking this because I have created such a page, I have hardcoded the redirect to this page, but instead a simple display of the confirm page it's always scrolling down to the #kformname0 anchor.

Thank you.
@atisz,
Is there a way to display a success message after form submit, on a custom page ..

A simple redirect to the custom page upon successful form submission should do it -
Code: Select all
<cms:if k_success >
    <cms:redirect 'place link to your custom success page here' />   
</cms:if>

I have hardcoded the redirect to this page, but instead a simple display of the confirm page it's always scrolling down to the #kformname0 anchor.

That can only mean that the visitor is still on the same page after submission and the redirect did not happen.
Please check your redirection code (and that is is placed within the 'k_success' block).
7 posts Page 1 of 1