Forums

TCPDF - create condition in PDF result

lselbach 10 Jul, 2014
Hi there!

I´m making a PDF using data input to build a contract.

But there is an 'optional field', so, if the user fills in, the result is one text on the contract. If he leave blank, the result is another.

The name of the field is RAZAOSOCIAL.

I´ve tried this code (assuming that I´m terribly bad with PHP):

<?php if  ('{$form->data['razaosocial']}' == '') echo 'inscrito/a no CPF sob nº {cpf}, ' else echo 'inscrito/a no CPF sob nº {cpf}, representando a empresa {razaosocial}, inscrita no CNPJ sob no. {cnpj},'; ?>


All the other things I wanted are working - thanks a lot!

Regards
Lucas Selbach
Brasil
lselbach 10 Jul, 2014
BTW, this code is within TCPDF action, in the field CONTENT, inside HTML code.
GreyHead 12 Jul, 2014
Hi Lucas,

It may be simpler to do this using a Custom Code action before the TCPDF action
<?php
if  ( $form->data['razaosocial'] == '') {
  $form->data['cpf_xxx'] = "inscrito/a no CPF sob nº {$form->data['cpf']}, ";
} else {
  $form->data['cpf_xxx'] = "inscrito/a no CPF sob nº {$form->data['cpf']}, representando a empresa {$form->data['razaosocial']}, inscrita no CNPJ sob no. {$form->data['cnpj']},"; 
?>
Then put {cpf_xxx} in the TCPDF content.

Bob

PS Or it may be that fixing your PHP is enough. There is a mixture of quotes and brackets that aren't quite right.
lselbach 12 Jul, 2014
Hi Bob,

Thanks for replying!!

Sorry, but It dind´t worked!

Both the option (with or without info) get the label itself on PDF . Take a look
http://lucasselbach.com.br/contratos/Contrato_video__20140712195038.pdf

Any suggestion?

Thanks for helping and best regards!
Lucas
GreyHead 13 Jul, 2014
HI Lucas,

It works perfectly when I test it with a very simple form :-(

To debug add a debugger action to the form ON Submit event and a Show Stopper action and drag them both up before the TCPDF action, That will stop the PDF being created and let you see what the output from the PHP is.

Bob
lselbach 14 Jul, 2014
Hi Bob,

I did that, and the result is below.

If you can take a look, that would be awesome.

Thanks
Lucas
GreyHead 14 Jul, 2014
Hi Lucas,

I don't see any value there for [cpf_xxx] or anything similar . . . maybe there's a typo in the PHP?

Bob
lselbach 14 Jul, 2014
Not sure what´s happening - take a look
GreyHead 15 Jul, 2014
Hi Lucas,

The last line of your PHP isn’t PHP. Please try deleting it.

Bob
lselbach 15 Jul, 2014
Dear Bob,
I don´t understand: this is EXACTLY what you´ve posted above
<?php
if  ( $form->data['razaosocial'] == '') {
  $form->data['cpf_xxx'] = "inscrito/a no CPF sob nº {$form->data['cpf']}, ";
} else {
  $form->data['cpf_xxx'] = "inscrito/a no CPF sob nº {$form->data['cpf']}, representando a empresa {$form->data['razaosocial']}, inscrita no CNPJ sob no. {$form->data['cnpj']},"; 
?>


So I tried with an empty form and also didn´t worked.

Can you send me the form you´ve tested so I install here and test too??

Thanks
Lucas
GreyHead 16 Jul, 2014
Hi Lucas,

Sorry, my mistake. I misread the code in the strange image viewer here :-(

Here's my test form

Bob
lselbach 17 Jul, 2014
Hi Bob

The thing is that {cpf_xxx} doesn´t load on TCPDF action. (Even taking off underscore to {cpfxxx}

I also tried a simple code and still doesn´t work.
<?php 
   $form->data['cpfxxx'] == $form->data['razaosocial'] 
?>


Or another version of code, based on what you´ve sent me
<?php
if  ( $form->data['razaosocial'] <> '') {
  $form->data['cpfxxx'] = 'inscrito/a no CPF sob nº '.$form->data['cpf'].' 
  representando a empresa '.$form->data['razaosocial'].' inscrita no CNPJ sob no. '.$form->data['cnpj']; 
} else {
  $form->data['cpfxxx'] = 'inscrito/a no CPF sob nº '.$form->data['cpf'];
?>


Still doesn´t work.
Should I send you the form??

regards
Lucas
lselbach 17 Jul, 2014
BTW, the CC field in EMAIL action can be filled with a fixed email? like me@provider.com ?
Because I did that and it´s not working!!

Thanks
Lucas
GreyHead 17 Jul, 2014
Hi Lucas,

The last code snippets you posted are missing a ; in the first one and a final } in the second. Please check the PHP carefully.

By all means send me a form backup.

Yes you can use a standard email address in the static CC box of an email action.

Bob
GreyHead 18 Jul, 2014
Hi Lucas,

Thanks for the copy of the form; as far as I can tell it works perfectly provided that you fix the typos in the PHP - see my earlier post.

Bob
lselbach 21 Jul, 2014
Dear Bob,
It was missing a BRACKET in the end.

The correct code is

<?php
if  ( $form->data['razaosocial'] <> '') {
  $form->data['cpfxxx'] = 'inscrito/a no CPF sob nº '.$form->data['cpf'].' 
  representando a empresa '.$form->data['razaosocial'].' inscrita no CNPJ sob no. '.$form->data['cnpj']; 
} else {
  $form->data['cpfxxx'] = 'inscrito/a no CPF sob nº '.$form->data['cpf'];
}
?>


Do you know how to JUSTIFY THE PARAGRAPH??

Regards
Lucas
GreyHead 22 Jul, 2014
Hi Lucas,

Good to see you found the typo.

I don't much like justified text in HTML but you can try adding CSS to the paragraph - I expect that will work OK.

Bob
lselbach 22 Jul, 2014
Great, Bob,
Thanks for your precious help!

BTW, just to let you know that when I make login it appears 'Invalid Token' and I have to go back on the browser.

Best Regards
Lucas
GreyHead 22 Jul, 2014
Hi Lucas,

I think that the 'Invalid token' is a Joomla! feature, not a CF one :-(

Bob
This topic is locked and no more replies can be posted.