Replies: 1   Views: 1757
Replacevariablebytext seems to fail randomly on only one or two fields
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by cem  · 08-08-2019 - 20:41


We have the Enterprise license for v.7 installed in a production server.  We've noticed that when a new .docx template is created, sometimes randomly a field will not take the variable data passed to it.  I have examples of this and I can usually recreate the problem.  This seems to go away if I edit the .docx and simply re-type the variable.  I can't say for sure what causes this because it does seem to change.  I can literally copy the .docx as a test version and the original will be fine, but the copy will again leave the field without putting in the data.  I've confirmed over and over that the data is present and that the fieldnames match (no typo, etc) but it definitely will fail. 

Is there some known bug or field or symbol we should avoid?  We use ^ as the symbol and I notice this happens sometimes in the footer more than other "regular" parts of the .docx.  One example that almost consistently does this is at the beginning of the line in the footer we will have ^cus_num^.  Could it be related to the ^ symbol?  The fact that it starts the line off and is numeric data?  The underscore in the field (we use underscores with no problem elsewhere)?  I can literally copy that field from the footer and place it above in the body and one spot will work and the other will not!  There is no special formatting on the text field, it is normal. 

Here is a snippet (the other data will be fine but not cus_num):

        $footvar = array(
          'acct_code'   => $data['common']['c_acct_code'],
          'prevnum'     => (!empty($data['quote']['QuotePrevNum'])) ? $data['quote']['QuotePrevNum'] : 'NEW',
          'quote_num'   => $data['quote']['QuoteNumber'],
          'eb'          => $eb,
          'cus_num'     => (!empty($data['customer']['CustomerNumber'])) ? $data['customer']['CustomerNumber'] : 'New'
        $foot = array('target' => 'footer');
        $docx->replaceVariableByText($footvar, $foot);

Regards, cem