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

I have a form in a modal window and use

<cms:if k_success >
<cms:redirect "<cms:show k_page_link />" />
</cms:if>

Somehow on submitting the form I have to reload the page again to have the new data available. Is my code correct ?

The form :
Code: Select all
<div id="nworderline" class="reveal-modal" data-reveal aria-hidden="true" role="dialog">
  <!-- start form -->
<cms:form
    masterpage='sales-transactions.php'
    mode='create'
    enctype='multipart/form-data'
    method='post'
    anchor='0'
    >

<cms:set my_action="create_page_k_template_id"/>

<cms:if k_success >

<cms:validate_nonce my_action />

<cms:set line_price = "<cms:show frm_price/>"/>
<cms:set line_amount = "<cms:show frm_amount/>"/>
<cms:set total_price = "<cms:mul line_price line_amount/>"/>




        <cms:db_persist_form
            _invalidate_cache='0'
            k_page_title="<cms:show sa/><cms:show sa_no/>-<cms:show frm_item/>"
            invoice_no="<cms:show sa_no/>"
            total="<cms:show total_price/>"
            invoice="<cms:show k_page_id/>"   
        />

  <cms:redirect "<cms:show k_page_link />" />

      <!-- Delete this  <cms:redirect "<cms:link k_page_link />" />
            <cms:redirect "<cms:login_link />" />



FIXME: @reload [how to] try to solve refresh page only the first time page shows new line direct
<script>parent.location.reload(true)</script> -->


</cms:if>

<div class="row collapse">

<div class="small-3 large-2 columns">
      <span class="prefix">Description</span>
    </div>

<div class="small-9 large-10 columns">
<cms:input type="bound" name="item" placeholder="Like: Russell t-shirts blue size M" />
</div>

</div>

<div class="row collapse">

<div class="small-3 large-2 columns">
      <span class="prefix">Amount</span>
    </div>

<div class="small-9 large-10 columns">
<cms:input type="bound" name="amount" placeholder="Like: 5000" />
</div>

</div>

<div class="row collapse">

<div class="small-3 large-2 columns">
      <span class="prefix">Price</span>
    </div>

<div class="small-9 large-10 columns">
<cms:input type="bound" name="price" placeholder="Like: 5" />
</div>

</div>

<cms:if (my_user_team=='Accounting') || (my_user_team=='Management') >

<div class="row collapse">

<div class="small-3 large-2 columns">
      <span class="prefix">VAT</span>
    </div>

<div class="small-9 large-10 columns">
<cms:input type="bound" name="vat" placeholder="24" />
</div>

</div>
<br/>

</cms:if>

<cms:input name='nonce' type='hidden' value="<cms:create_nonce my_action />" />

<input type="submit" name="submit" class="button small" value="Submit"/>

</cms:form>

   <a class="close-reveal-modal">&#215;</a>
   
</div>



The page :
Code: Select all
<?php require_once( 'couch/cms.php' ); 
/**
* Page template crm project.
* CRM Based on [CouchCMS](http://www.couchcms.com/)
*/
?>

<!-- TODO: @Print [as PDF or send Mail] for Quote and Invoices -->

<cms:template title='Sales' clonable='1' commentable='1' dynamic_folders='1'>

<cms:editable name='system' label='System' type='group' order='1'/>
<cms:editable name='sa' label='Prefix' type='text' required='1' group='system'>SA-</cms:editable>
<cms:editable name='sa_no' label='Sales Number' type='text' validator='non_negative_integer' search_type='integer' required='1' group='system'></cms:editable>
<cms:editable name='owner' label='Owner' type='text' required='1' group='system' search_type='integer' ></cms:editable>


<cms:editable type='relation' name='company' masterpage='companies.php' has='one' />

<cms:editable name='info' label='Order info' type='group' order='3'/>
<cms:editable name='order_note' label='Extra info' type='richtext' group='info'></cms:editable>



<cms:editable name='terms' label='Terms' type='group' order='3'/>

<cms:editable name="payment" label="Payment Terms" desc="Select one from these"
    opt_values='prepay=0 | 7 days=7 | 30 days=30'
    opt_selected = '7 days'
    type='dropdown'
    search_type='integer'
    required='1'
    group='terms'
  />

<cms:editable name='note' label='Note' type='textarea' group='terms'></cms:editable>


<cms:editable name='due_date' label='Date due' type='text'></cms:editable>
<cms:editable name='invoice_date' label='Invoice date' type='text'></cms:editable>
<cms:editable name='invoice_number' label='Invoice Number' type='text' search_type='integer'></cms:editable>


</cms:template>


<!DOCTYPE html>
<html>

  <head>
   
    <cms:embed 'head.html'/>
 
  </head>
 
    <cms:embed 'topbar.html'/>
 

<body>
 
  <cms:embed 'banner.html'/>
 
 
   <div class="row"> <!-- main row -->
     <div class="large-12 columns">
       
       
         <div class="space"></div>
         
                       
          <cms:if k_logged_in && (my_user_team=='Sales') || (my_user_team=='Management') >
             
                      <cms:set cur_status = "<cms:show sa/>" 'global' />
                      <!-- cur_status is used to for checking status invoice or quote -->
                      <!-- NOTE: @cookie [set for edit_order.php] see cheesypoof solution -->
                      <cms:set_cookie name='linked_page' value=k_page_link expire='0'/>
                     
                       
                      <cms:if k_is_home >
                        <cms:embed 'list-view/sales-list.html'/>
                      </cms:if>
                     
                      <cms:if k_is_page >
                        <cms:embed 'page-view/sales-order.html'/>
                      </cms:if>                         
             
                 <cms:dump />
           
            <cms:else />
             
              <div class="panel callout">You should be logged in to view this page !</div>
          </cms:if>

         
     </div><!-- end large-12 columns -->
     
     
   </div> <!-- end main row -->
     
   
   
    <cms:embed 'footer.html' />
   
   
</body>

</html>

<?php COUCH::invoke(); ?>
     


Code: Select all
          <div class="row">

              <div class="small-12 medium-12 large-4 columns">
               
               <cms:set cur_date="<cms:date format='Y-m-d H:i:s'/>" 'global'/>
               <cms:set alert_date="<cms:date due_date format='Y-m-d H:i:s'/>" 'global'/>
                  <cms:if (alert_date lt cur_date) && (cur_status=='In')>
                   <p class='panel-red'>Invoice overdue since: <cms:date due_date format='d-m-Y'/><p>
                  </cms:if>
              </div>


              <div class="small-12 medium-12 large-4 columns">
                <p><small>Date Posted: <cms:date k_page_date format='d-m-Y'/></small></p>
              </div>
 
           </div>

       <fieldset>
         <legend><cms:if k_page_foldername='quote'>Quote: <cms:show sa/><cms:show sa_no/><cms:else/>Invoice: <cms:show sa/><cms:show invoice_number/></cms:if></legend>
               <br/>
              <cms:related_pages 'company' masterpage='companies.php' > <!-- All variables of 'companies.php' are available here -->
     
                 <div class="small-12 medium-4 large-4 columns">
     
                   <h5 class="l-title"><a href="<cms:show k_page_link/>"><cms:show k_page_title /></a></h5>
                   <p><cms:show company_street />  <cms:show company_streetno /><br/><cms:show company_town /> <cms:show company_postcode /><br/><cms:show company_country /> </p>
                 </div>

             </cms:related_pages>
             
                           <hr/>

              <table width="100%">
               <tr>
                 <th>Description</th>
                 <th style="text-align:right">Amount</th>
                 <th style="text-align:right">Price</th>
                 <th style="text-align:right">Total</th>
                 <th>VAT</th>
                   <cms:if k_page_foldername='quote'> 
                      <th></th>
                      <th></th>
                   </cms:if> 
               </tr>

               <cms:set total_price_count='0' scope='global' />
               <cms:set total_vat_count='0' scope='global' />
               
               
               <cms:pages masterpage='sales-transactions.php' limit='50' paginate='1' custom_field="invoice_no==<cms:show sa_no/>" order='asc'>
                 <tr>
                   <td><cms:show item /></td>
                   <td style="text-align:right"><cms:show amount /></td>
                   <td style="text-align:right"><cms:show price /></td>
                 
                   <td style="text-align:right">
                      <cms:embed 'blocks/calc-totalPrice-orderline.html'/>
                   </td>
                   
                     <!-- calculate invoice total -->
                       <cms:set invoice_line-price = "<cms:show total_price/>"/><cms:set total_price_count="<cms:add total_price_count invoice_line-price />" scope='global' />
                       <cms:set invoice_line-vat = "<cms:show total_vat_price/>"/><cms:set total_vat_count="<cms:add total_vat_count invoice_line-vat />" scope='global' />
                     <!-- calculate invoice total -->

                   <td><cms:show vat />%</td>
                   
                   <td><i class="fi-page-edit alert"></i></td>
                   <td><i class="fi-trash alert"></i></td>
                   
                 </tr>
                 
               </cms:pages>
               
               </table>
               
                  <!-- here total ordercalc -->
                     <div align="right">
                        <table>
                          <td>Total ex VAT: <cms:number_format total_price_count decimal_precision='2' decimal_character=',' thousands_separator='.'/></td>
                          <td>VAT
                            <cms:set total_ex_vat = "<cms:show total_price_count/>" />
                            <cms:set total_incl_vat = "<cms:show total_vat_count/>" />
                            <cms:set vat_calc="<cms:sub total_incl_vat total_ex_vat />" scope='global' /><cms:number_format vat_calc decimal_precision='2' decimal_character=',' thousands_separator='.'/>
                          </td>
                          <td><b>Total <cms:number_format total_vat_count decimal_precision='2' decimal_character=',' thousands_separator='.'/> €<b/></td>
                       </table>

                       <p align="right"><small>Payment Terms: <cms:show payment/> Days</small></p>
                       <cms:set payday="<cms:show payment/>" 'global' search_type='integer'/><!-- for invoice date settings -->
                    </div>
                 <!-- end here total ordercalc -->
                 
               
                   <cms:if k_page_foldername='quote'>
                     <p class='button tiny success' data-reveal-id="nworderline" data-reveal-ajax="true">Add Row</p>
                   </cms:if>

         
        </fieldset>
       
       
        <cms:embed 'forms/nworderline.html' />

     


Thanks
I load frameworks and write bugs on top of them, after that I rearrange the code so that it looks like a cool product.
Tom,

As far as I can see, the <cms:redirect "<cms:show k_page_link />" /> code should cause the current page to refresh automatically.

On probable reason for this not happening could be that the form submission is being intercepted to be made through AJAX (perhaps the front-end framework is doing this automatically). Can you please check and let me know if that is the case?

Thanks.
Hi KK,

I did try this with and without ajax. I get the feeling it maybe reloads the page faster then the database is updated, when I resfresh the page again or submit the form again it works as it should.

Thanks again
I load frameworks and write bugs on top of them, after that I rearrange the code so that it looks like a cool product.
Can you PM me the access creds of your site (FTP+Couch) please?
Allow me to take a look at this issue first-hand.

Thanks.
Thanks for the creds, Tom.

I had a look and I really should have figured out the problem a long time back.

This is what seems to be happening -
1. You use DBF to create a new cloned page (of sales-transactions.php)
2. Redirect to refresh the page
3. Use cms:pages to list the pages (of sales-transactions.php) which now should also show the latest page we created in step 1.

The problem is that sometimes you get to see the page while sometime you need to refresh again before the new page appears in the list.

Please make the following amendment to your cms:pages listing and the problem should be resolved -
<cms:pages masterpage='sales-transactions.php' limit='50' show_future_entries='1' ...

This is a corner-case that came to light after DBF was introduced.

What is happening is that the time value cms:pages uses to figure out if a page is in 'future' or not has a resolution of one 'second' (and not 'milli-second').

So when you create a page and refresh immediately, if the time gap between the two events is less that a second, the newly created page is considered 'future' till the current second is past (when you refresh the second time, definitely a second has passed so the page always appears).

For legacy reasons I cannot make changes to the core to take this last second into account.
So the solution for now is to simply ask cms:pages to show even future pages by setting its 'show_future_entries' parameter to '1'.

In fact, if you take a look at the code that accompanies our advanced tutorial (http://www.couchcms.com/docs/advanced-tutorial/), all the instances of cms:pages tag have the 'show_future_entries' parameter set to avoid this very problem.

It somehow skipped my mind to mention this in the tutorial, I'm sorry for that.

Hope this helps.
Hi KK,

Many thanks to take the time to look into this. I didn't know about the 'show_future_entries' before, I guess I should be more alert and better read the docs you publish.
I load frameworks and write bugs on top of them, after that I rearrange the code so that it looks like a cool product.
6 posts Page 1 of 1