Hi Group,
I have an accident form that is completed on our construction projects when there is an incident or injury. The people complete this form and submit. I use the Hooks to generate an email notification that goes out to principals in our company. The problem I want to resolve is unwanted characters that seem to be coming from the database. If the user includes "Quotes" or a carriage return in their information, the resulting email message has additional unwanted symbols. I hope there is a fix and I don't just have to live with this. Please bear in mind if you reply, I'm not a coder and you'll have to help me out with some basic instructions on how to implement any ideas you might have.
Thanks in advance!
Ray
Unwanted Characters in Data
Unwanted Characters in Data
- Attachments
-
- carriage_return.JPG (113.75 KiB) Viewed 2904 times
Re: Unwanted Characters in Data
Hi,
depending on the function you use to send mail, you may need to adjust some code.
When you use the AG function sendmail (in incFunctions.php) you may want to use nl2br for encoding the message:
See https://www.php.net/manual/en/function.nl2br.php
Or use htmlspecialchars ( https://www.php.net/manual/de/function. ... lchars.php )
Olaf
depending on the function you use to send mail, you may need to adjust some code.
When you use the AG function sendmail (in incFunctions.php) you may want to use nl2br for encoding the message:
Code: Select all
sendmail(array(
'to' => $email,
'name' => $memberID,
'subject' => $subject,
'message' => nl2br($message)
));
Or use htmlspecialchars ( https://www.php.net/manual/de/function. ... lchars.php )
Olaf
Some postings I was involved, you might find useful:
SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button; Place a search on details view
SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button; Place a search on details view
Re: Unwanted Characters in Data
Thank you for the reply onoehring,
I tried to insert the nl2br into my Hooks code but get an error. My code looks somewhat different than your example. I'm using an array to send the email message to many recipients using sendmail. All of this coding has been put together with the help of others in this forum and AppGini support.
Where exactly do I insert the nl2br with the code as I have it in my hook file??
Thank you again.
Ray
I tried to insert the nl2br into my Hooks code but get an error. My code looks somewhat different than your example. I'm using an array to send the email message to many recipients using sendmail. All of this coding has been put together with the help of others in this forum and AppGini support.
Where exactly do I insert the nl2br with the code as I have it in my hook file??
Thank you again.
Ray
Code: Select all
$receipt=array([email protected]','[email protected]');
foreach ($receipt as $address){
$projectname = sqlValue("select name from project where id='{$data['project']}'");
sendmail(array(
// mail recipient
'to' => $address,
'name' => "",
// subject
'subject' => "An injury report has been submitted for " . sqlValue("select name from project where id='{$data['project']}'"),
// message
'message' => "The following Injury Report was submitted by {$memberInfo['username']}<br> This is a preliminary report, details may change. \n\n"."<br>
- aarlauskas
- Veteran Member
- Posts: 127
- Joined: 2019-04-28 18:03
- Location: Medway, UK
Re: Unwanted Characters in Data
I see this often in my emails too after submitting the form. No special characters or so in the fields, but email data comes with some nonsence as per this post \n\r blah. Interested to see what cases it as well.
Re: Unwanted Characters in Data
Hi,
I would suggest trying this
or replacing my inserted nl2br with htmlspecialchars.
Olaf
I would suggest trying this
Code: Select all
$receipt=array([email protected]','[email protected]');
foreach ($receipt as $address){
$projectname = sqlValue("select name from project where id='{$data['project']}'");
sendmail(array(
// mail recipient
'to' => $address,
'name' => "",
// subject
'subject' => "An injury report has been submitted for " . sqlValue("select name from project where id='{$data['project']}'"),
// message
'message' => nl2br("The following Injury Report was submitted by {$memberInfo['username']}<br> This is a preliminary report, details may change. \n\n"."<br>)
Olaf
Some postings I was involved, you might find useful:
SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button; Place a search on details view
SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button; Place a search on details view
Re: Unwanted Characters in Data
Hi Olaf,
Thank you so much for trying to help a rookie out! I tried adding both of your suggestions to the code but get an error. It seems to me that in the call- 'message' => that the opening and closing quote marks are negated by the addition of the parenthesis that you indicate. It appears that I must have a closing quote mark a the end of my email message? I am including the entire message below to give a better picture....Thanks again!
Thank you so much for trying to help a rookie out! I tried adding both of your suggestions to the code but get an error. It seems to me that in the call- 'message' => that the opening and closing quote marks are negated by the addition of the parenthesis that you indicate. It appears that I must have a closing quote mark a the end of my email message? I am including the entire message below to give a better picture....Thanks again!
Code: Select all
// message
'message' => "The following Injury Report was submitted by {$memberInfo['username']}<br> This is a preliminary report, details may change. \n\n"."<br>
<p>
<p><strong>Project:</strong> $projectname
<br>
<table>
<tbody>
<tr>
<td><strong>Date of Injury</strong></td>
<td> </td>
<td><strong>Time of Injury </strong></td>
</tr>
<tr>
<td>{$data['date']}</td>
<td></td>
<td>{$data['time']}</td>
</tr>
</tbody>
</table>
<p>
<Strong><h3>Injured Worker Details</h3></strong>
<table>
<tbody>
<tr>
<td><strong>First Name </strong></td>
<td><strong>Last Name </strong></td>
<td><strong>Craft</strong> </td>
<td><strong>D.O.B.</strong> </td>
</tr>
<tr>
<td>{$data['fname']}</td>
<td>{$data['lname']}</td>
<td>{$data['craft']}</td>
<td>{$data['dob']}</td>
</tr>
</tbody>
</table>
<h3>Injury Details</h3>
<p><strong>Injury Severity:</strong> {$data['severity']}
<p><strong>Type of Injury:</strong> {$data['injury']}
<p><strong>Body Part</strong> {$data['body_part']}
<p><strong>Treatment Provided:</strong> {$data['treatment']}</p>
<p><strong>Treated By:</strong> {$data['treat_by']}</p>
<p><strong>Mode of Injury:</strong> {$data['event']}</p>
<p><strong>Event Description:</strong> {$data['event_desc']}</p>
<p><strong>Source of the Injury:</strong> {$data['source']}</p>
<p><strong>Injury Source Details:</strong> {$data['source_desc']}</p>
<p><strong>What was the employee doing just before the incident occurred? </strong> {$data['action']}, {$data['action_desc']}
<p><strong>What object or substance directly harmed the employee? </strong> {$data['object']}, {$data['object_desc']}
<p><strong>Direct Cause:</strong> {$data['direct_cause']}</p>
<p><strong>Indirect Cause:</strong> {$data['indirect_cause']}</p>
<p><strong>Basic Cause:</strong> {$data['basic_cause']}</p>
<p><strong>Causation Rationale:</strong> {$data['cause_explain']}</p>
<p><strong>Workplace Layout Issues:</strong> {$data['workplace']}</p>
<p><strong>Workplace Layout Explanation:</strong> {$data['work_explain']}</p>
<p><strong>Behavior Based Safety Factor:</strong> {$data['bbs']}</p>
<p><strong>Authors comments:</strong> {$data['comments']}</P>",
));
}
return TRUE;
}
Re: Unwanted Characters in Data
Hi,
maybe I missed something. I copied your code from the previous posting. Addon: You might throw some variable into the message (see my second sugegstion)
Olaf
maybe I missed something. I copied your code from the previous posting. Addon: You might throw some variable into the message (see my second sugegstion)
Code: Select all
$yourTEXT = "The following Injury Report was submitted by {$memberInfo['username']}<br> This is a preliminary report, details may change. \n\n"."<br>
<p>
<p><strong>Project:</strong> $projectname
<br>
<table>
<tbody>
<tr>
<td><strong>Date of Injury</strong></td>
<td> </td>
<td><strong>Time of Injury </strong></td>
</tr>
<tr>
<td>{$data['date']}</td>
<td></td>
<td>{$data['time']}</td>
</tr>
</tbody>
</table>
<p>
<Strong><h3>Injured Worker Details</h3></strong>
<table>
<tbody>
<tr>
<td><strong>First Name </strong></td>
<td><strong>Last Name </strong></td>
<td><strong>Craft</strong> </td>
<td><strong>D.O.B.</strong> </td>
</tr>
<tr>
<td>{$data['fname']}</td>
<td>{$data['lname']}</td>
<td>{$data['craft']}</td>
<td>{$data['dob']}</td>
</tr>
</tbody>
</table>
<h3>Injury Details</h3>
<p><strong>Injury Severity:</strong> {$data['severity']}
<p><strong>Type of Injury:</strong> {$data['injury']}
<p><strong>Body Part</strong> {$data['body_part']}
<p><strong>Treatment Provided:</strong> {$data['treatment']}</p>
<p><strong>Treated By:</strong> {$data['treat_by']}</p>
<p><strong>Mode of Injury:</strong> {$data['event']}</p>
<p><strong>Event Description:</strong> {$data['event_desc']}</p>
<p><strong>Source of the Injury:</strong> {$data['source']}</p>
<p><strong>Injury Source Details:</strong> {$data['source_desc']}</p>
<p><strong>What was the employee doing just before the incident occurred? </strong> {$data['action']}, {$data['action_desc']}
<p><strong>What object or substance directly harmed the employee? </strong> {$data['object']}, {$data['object_desc']}
<p><strong>Direct Cause:</strong> {$data['direct_cause']}</p>
<p><strong>Indirect Cause:</strong> {$data['indirect_cause']}</p>
<p><strong>Basic Cause:</strong> {$data['basic_cause']}</p>
<p><strong>Causation Rationale:</strong> {$data['cause_explain']}</p>
<p><strong>Workplace Layout Issues:</strong> {$data['workplace']}</p>
<p><strong>Workplace Layout Explanation:</strong> {$data['work_explain']}</p>
<p><strong>Behavior Based Safety Factor:</strong> {$data['bbs']}</p>
<p><strong>Authors comments:</strong> {$data['comments']}</P>"';
$receipt=array([email protected]','[email protected]');
foreach ($receipt as $address){
$projectname = sqlValue("select name from project where id='{$data['project']}'");
sendmail(array(
// mail recipient
'to' => $address,
'name' => "",
// subject
'subject' => "An injury report has been submitted for " . sqlValue("select name from project where id='{$data['project']}'"),
// message
'message' => nl2br($yourTEXT),
... MESSAGE IS IN YOUR NEW $yorTEXT VARIABLE...
..... HERE IS SOMETHING MISSING IN YOUR CODE ... AT LEAST 2 CLOSING ). YOU MIGHT WANT TO REMOVE THE , AFTER THE MESSAGE
return TRUE;
}
Olaf
Some postings I was involved, you might find useful:
SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button; Place a search on details view
SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button; Place a search on details view
Re: Unwanted Characters in Data
Hi Olaf,
I tried your new code but still get the unwanted characters in the email message.
The characters don't appear in the database, so I'm assuming that the PHP is injecting them?? Any other ideas?
I tried your new code but still get the unwanted characters in the email message.
The characters don't appear in the database, so I'm assuming that the PHP is injecting them?? Any other ideas?
Re: Unwanted Characters in Data
Olaf!!
I used the link you provided to PHP String Functions and found this "stripcslashes". That worked to remove the characters I don't want, but it also removed the line breaks. But, at least I'm moving in the forward direction!! Thank you for offering your time to help with my problem.
I used the link you provided to PHP String Functions and found this "stripcslashes". That worked to remove the characters I don't want, but it also removed the line breaks. But, at least I'm moving in the forward direction!! Thank you for offering your time to help with my problem.
Re: Unwanted Characters in Data
Olaf,
This seemed to work:
// message
'message' => nl2br (stripcslashes($yourTEXT)),
This seemed to work:
// message
'message' => nl2br (stripcslashes($yourTEXT)),
Re: Unwanted Characters in Data
Hi,
thank you for sharing.
Olaf
thank you for sharing.
Olaf
Some postings I was involved, you might find useful:
SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button; Place a search on details view
SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button; Place a search on details view