Is there a way to clear the form after a successful POST?
However, IMHO, the following method is the cleanest -
Suppose this is the form we are dealing with
- Code: Select all
<cms:form method='post' anchor='0'> <cms:if k_success > .. take action like sending email etc. .. </cms:if> <cms:input name='first_name' type='text' /> <button type="submit">Submit</button> </cms:form>
After whatever action you want to take in the success condition, simply add a redirect statement like this -
- Code: Select all
<cms:form method='post' anchor='0'> <cms:if k_success > .. take action like sending email etc. .. <cms:redirect k_page_link /> </cms:if> <cms:input name='first_name' type='text' /> <button type="submit">Submit</button> </cms:form>
While redirecting will clear up the form data, we'd ideally also want to show some kind of a success message to the visitor. This can be done using the 'flash variables' -
- Code: Select all
<cms:if "<cms:get_flash 'submit_success' />" > <h2> Thank you for contacting us. </h2> </cms:if> <cms:form method='post' anchor='0'> <cms:if k_success > .. take action like sending email etc. .. <cms:set_flash 'submit_success' '1' /> <cms:redirect k_page_link /> </cms:if> <cms:input name='first_name' type='text' /> <button type="submit">Submit</button> </cms:form>
If you happen to get an error message complaining that tags 'get_flash' or 'set_flash' are unknown, please enable the 'session' addon by uncommenting the following line in 'couch/addons/kfunctions.php' file (if kfunctions is not present in the said folder, you'll have to rename the 'kfunctions.example.php' to 'kfunctions.php' first).
- Code: Select all
//require_once( K_COUCH_DIR.'addons/cart/session.php' );
Hope this helps.