Problems, need help? Have a tip or advice? Post it here.
4 posts Page 1 of 1
Hi

I can't get the error or success messages after submiting a form.
My form is a DBF inside a bootstrap modal window.
Even though I use 'cms:set_flash' and 'cms:get_flash' to set and get the success or error messages, it seems these are gone after the form submission.

Here is my code:
Code: Select all
<?php require_once( 'couch/cms.php' ); ?>
<cms:template title='mytemplate' clonable='1'>
   <cms:editable name='message' type='text' required='1' />
</cms:template>
<html lang="en">
<head>
   <link rel="stylesheet" href="css/bootstrap.min.css">
</head>
<body>
   <div class="container">
      <div class="row">
         <cms:get_flash name='alert' />
         <cms:if alert>
            <h3>Your form was not submitted</h3>
            <cms:each alert sep='\n'>
                  <cms:show item /><br>
               </cms:each>
         </cms:if>
         <cms:get_flash name='success' />
         <cms:if success>
            <h3>Your form is submitted</h3>
            <cms:each success sep='\n'>
                  <cms:show item /><br>
               </cms:each>
         </cms:if>
      </div>
      <div class="row">
         <cms:pages masterpage='test-modal.php' >
            <cms:show message /><br />
         </cms:pages>
      </div>
      <div class="row">
         <a href="#" data-toggle="modal" data-target="#add" >
            <button type="button" class="btn btn-lg">Add a message <span class="glyphicon glyphicon-plus" aria-hidden="true"></span></button>
         </a>
      </div>
      <div id="add" class="modal fade" tabindex="-1">
         <div class="modal-dialog">
            <div class="modal-content">
               <div class="modal-header bg-info">
                  <button type="button" class="close" data-dismiss="modal">&times;</button>
                  <h4 class="modal-title">Add your message</h4>
               </div>
               <cms:form
                  name='create_record'
                  masterpage='test-modal.php'
                  mode='create'
                  enctype='multipart/form-data'
                  method='post'
                  anchor='0'
                  >

                  <cms:if k_success >
                     <cms:db_persist_form
                        _invalidate_cache='0'
                        _auto_title="1"
                        />

                     <cms:set_flash name='success' value=k_success />
                     <cms:redirect url="<cms:link masterpage='test-modal.php' />" />
                  </cms:if>

                  <cms:if k_error >
                     <cms:set_flash name='alert' value=k_error />
                     <cms:redirect url="<cms:link masterpage='test-modal.php' />" />
                  </cms:if>
                 <div class="modal-body">
                     <div class="row">
                        <div class="col-md-12">
                           <div class="form-group">
                             <label for="input_message">Your message</label>
                              <cms:input name='message' type='bound' class="form-control" id="input_message" placeholder="Give your feeedback here" />
                           </div>
                        </div>
                     </div>
                  </div>
                  <div class="modal-footer">
                     <button type="button" class="btn btn-link" data-dismiss="modal">Cancel</button>
                     <button type="submit" name='submit' class="btn btn-primary">Add</button>
                  </div>
               </cms:form>
            </div>
         </div>
      </div>
   </div>
   <script src="js/jquery.js"></script>
   <script src="js/bootstrap.min.js"></script>
</body>
</html>
<?php COUCH::invoke(); ?>
I'm expecting to see an error after submitted the form when the field 'message' is left empty as this one is defined as required in the template. But I don't...
Am I doing something wrong? And is there an easy way to get these error and success messages from the DBF?

NB:Apologies if this question already was answered. I google for it and saw some related post, but they don't have a solution to the issue I'm seeing.

This has error of unknown variable 'alert' in IF statement..
Code: Select all
<div class="row">
         <cms:get_flash name='alert' />
         <cms:if alert>
....


How about this:
Code: Select all
<div class="row">
         <cms:set alert = "<cms:get_flash name='alert' />" />
         <cms:if alert>
...

Same applies to 'success'.

Also, saving the form can fail as well as submitting. Adapting to it:
Code: Select all
                  <cms:if k_success >
                     
                     <cms:db_persist_form
                        _invalidate_cache='0'
                        _auto_title="1"
                        />

                     <cms:if k_persist_error >
                        <cms:set_flash name='alert' value=k_persist_error />
                     <cms:else />
                        <cms:set_flash name='success' value=k_success />
                     </cms:if>
                     <cms:redirect url="<cms:link masterpage='test-modal.php' />" />
                  </cms:if>

                  <cms:if k_error >
                     <cms:set_flash name='alert' value=k_error />
                     <cms:redirect url="<cms:link masterpage='test-modal.php' />" />
                  </cms:if>


Please try now, should work fine.

I thought the issue I saw was somewhat related to the modal window. That's not the case.
Thanks for pointing out my mistakes: I misused the get/set_flash tags, and I also didn't know about the k_persist_error.
The error and success messages are working fine now!

You are welcome. :)
k_persist_error is a variable that is being set for <cms:db_persist /> and <cms:db_persist_form />. Both k_error and k_persist_error are being set at the same time with identical values. I personally prefer a more distinguishable syntax.
4 posts Page 1 of 1
cron