Forums

Submitting form now results in error T_ENCAPSED_AND_WHITESPACE

MaestroC 14 Nov, 2018
We've had a pretty complex form done in V5 for several years now. Recently it has started throwing errors when a user submits it. Exact error is:

 0 - syntax error, unexpected ''/chronoforms/pdfs/SurveyForm/' (T_ENCAPSED_AND_WHITESPACE)

I've turned on debugging but it doesn't show me anything additional so I don't know where this is coming from. It appears to be saving the data to the database but it is not sending out the emails that it should after a user submits the form. Example of the form is here:

https://www.quantumleapuniversity.org/gps-survey?coach=56

Is this error due to something in the TCPDF creation code or is it somewhere else? In any case if no changes to the code of the form have been made is it possible an update to CF or TCPDF could be the cause of this error?

EDIT- I thought it might be related to TCPDF so I tried to install the action again with the version available in the CF downloads area. When I try to install the TCPDF action I get the error "Class ZipArchive not found".

SOLUTION FOUND? I had to turn my PHP on that entire account back down to 5.6. When I did so the error went away Is CF 5.0.17 not PHP7 compatible?
healyhatman 14 Nov, 2018
CF5 is getting pretty old now and yes there are increasing reports of incompatibilities with PHP7
GreyHead 14 Nov, 2018
Hi MaestroC,

I am only seeing one irritating PHP Notice with PHP 7.

The error message looks as though it might be coming somehow from the name of the TCPDF file being saved. Could that be it?

Bob
MaestroC 12 May, 2019
Sorry to reopen this but I am finally getting around to trying to fix this as I really need to get this site running on PHP7.1.

GreyHead, you mention you think it might be related to saving the file name. Would that be related to the TCPDF action or would it be somewhere else in the form?

Is there anything you can think of that is different between PHP5.6 and 7.1 that would affect that? The form saves just fine when I have it switched back to php5.6 but gives the (T_ENCAPSED_AND_WHITESPACE) error when I turn it up to 7.1.
GreyHead 13 May, 2019
Hi MaestroC,

It's probably due to some extra spaces somewhere - maybe in a file name or from some Custom Code.

I suggest that you make a copy of your form and try removing any custom code around the TCPDF action - that should help you pind down exactly what is causing this.

Note: I haven't seen this reported elsewhere so it probably isn't arising directly from the CF code.

Bob
MaestroC 01 Nov, 2019
Sorry to bring this one back up but still trying to figure it out. I'll paste below the custom code that might be causing the issue, however I have no idea what is wrong with it if it is. Does this look like something that might cause that issue?

This is the first one. It takes the data from the form and puts it into an email that is sent to a coach:

<?php
$mailer = JFactory::getMailer();
$config = JFactory::getConfig();
$sender = array(
$config->get( 'mailfrom' ),
$config->get( 'fromname' )
);
$userid = $form->data['coachnum'];
$mailer->setSender($sender);
$user = JFactory::getUser($userid);
$recipient = $form->data['Client']['coachemail'];
$mailer->addRecipient($recipient);
$subject = 'GPS Survey Form Response from '.$form->data['Client']['firstName'].' '.$form->data['Client']['lastName'];
$mailer->setSubject($subject);
/* $mailer->setSubject('Survey Form Response'); */
$body = '<h2>Survey Form Response</h2>'
. '<div>A client has submitted a survey with your Coach ID #. Please refer to the attached PDF.';
$mailer->isHTML(true);
$mailer->Encoding = 'base64';
$mailer->setBody($body);
$mailer->addAttachment($form->files["cf_pdf_file"]["path"]);
$send = $mailer->Send();
if ( $send !== true ) {
echo 'Error sending email: ' . $send->__toString();
} else {
//echo 'Mail sent';
}
?>

This is the second custom code action and the only one that actually mentions something that we see in the error. The full error actually reads:

0 - syntax error, unexpected ''/chronoforms/pdfs/SurveyForm/' (T_ENCAPSED_AND_WHITESPACE)

<?php
$form->files["cf_pdf_file"]["path"] = JPATH_COMPONENT.'/chronoforms/pdfs/SurveyForm/;?><?php echo "{cf_pdf_file}"; ?>

Any idea if either of these are the actual culprits?
GreyHead 03 Nov, 2019
Hi MaestroC,

The last piece of PHP you posted is missing a ‘ after Form/ That might be the problem.

Bob
MaestroC 19 Jun, 2020
Sorry for the long delay on replying to this. We've just left it on the back burner for so long but now are being forced into updating the php version.

Adding that ' to the Form/ fixed that part of the form. Thank you!

However that led to another problem. I'll provide a video link farther down to let you see the problem first hand in case it helps

There are actually two forms in this system. The initial survey form which that ' fixed just fine. The client fills out their survey and it submits with no problem including sending out a PDF copy of it.

But there is also a survey edit form where a coach views the client's survey and enters in their own comments. I noticed that it was throwing the same encapsed and whitespace error so I checked and found the ' missing from that form as well. I added it and that fixed the php7 error. Unfortunately though it opened up a different problem in that the survey edit form no longer sends out the attachment. With the ' added to the edit form code it no longer sends out a copy of the PDF when it sends the emails.

Here is a video that attempts to show the problem. I am hoping this is something as simple as the other fix was...

https://drive.google.com/file/d/1_62jEO_Bi8pWlcIiSs27qyRA2YVEpiLc/view
Max_admin 20 Jun, 2020
I would say make sure the file path is correct first by using an echo before the "addAttachment" call, is the file path correct and accessible ?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
MaestroC 21 Jun, 2020
Like I said, I'm not a programmer but let me take a shot at it. This is the line where it calls the attachment:

$mailer->addAttachment($form->files["pdf_coach"]["path"]);

If I put:

echo 'The file path is' $form->files["pdf_coach"]["path"];

right before that mailer line is that what you mean?
Max_admin 21 Jun, 2020
no, echo $form->files["pdf_coach"]["path"];
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
MaestroC 22 Jun, 2020
Thank you again for your help. I made a quick video to show the results of doing what you suggested. I am also adding a photo below that shows the output of the debugger which I forgot to show in the video. Not sure if it will help or not...

https://drive.google.com/file/d/1BAziBtVfAVbKc5Vc_p2RIJdVEOEqtIFo/view

Max_admin 22 Jun, 2020
what is {pdf_coach} ? what are you trying to get by that code ?

I understand that you are trying to attach a file from the server, if so then just use the full path to the file, if the file has been uploaded by the form then you can just get it by this code:
$form->files["pdf_coach"]['path']
Remove the "{pdf_coach}" part and the JPATH...etc
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.