Insert HTML code in WYSIWYG field
3 posts by 3 authors in: Forums > CMS Builder
Last Post: Monday at 11:35pm (RSS)
Hi
I wonder whether it is possible to insert HTML (and PHP) code into a WYSIWYG field as it can be done in a Separator type of field.
My code is the following:
<?php
// Ensure error reporting to catch potential issues
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Display the $RECORD array for debugging
//echo '<pre>';
//print_r($RECORD);
//echo '</pre>';
// Check if 'date_of_visit' exists and copy its value to a new variable
$dateOfVisit = isset($RECORD['date_of_visit']) ? htmlspecialchars($RECORD['date_of_visit']) : 'Ημερομηνία δεν είναι διαθέσιμη';
?>
request: <?php echo htmlencode(@$_REQUEST['date_of_visit']); ?>
<div>
<center>
<p>
Report
</p>
<div style="text-align: left;">
Athens
<?php
// Use the copied value
echo $dateOfVisit;
?>
</div>
<?php
// Display other fields
echo isset($RECORD['office']) ? htmlspecialchars($RECORD['office']) : 'Γραφείο δεν είναι διαθέσιμο';
echo ' / ';
echo isset($RECORD['type_of_visit']) ? htmlspecialchars($RECORD['type_of_visit']) : 'Τύπος επίσκεψης δεν είναι διαθέσιμος';
?>
</center>
</div>
Although the code's content is visible when inserted in the HTML block of a Separator type field, it produces a null when inserted into the WYSIWYG field as a default value.
Regards,
Andreas Lazaris
By Tim - Monday at 9:51am
Hello Andreas,
WYSIWYG fields are typically piped through TinyMCE and any HTML/Code you put through it is restructured/reformatted to be proper HTML structure and not executed on the server side (this includes stripping out unrecognized tags such as PHP tags).
There are ways to get the editor to not filter out any PHP code (for instance to save it in the database) but it is advised to be very careful with this as you can easily introduce a security risk. If anyone is able to put PHP code into one of those fields and it is executed by your server, that would be bad.
Another option would be to have your code run PHP first and then put its output into the editor when it initializes. It all really depends on what you are trying to accomplish. :)
Senior Web Programmer
Interactivetools.com
By Dave - Monday at 11:35pm
Hi Andreas,
Some additional thoughts on this.
The "default value" content in the field editor is only used when you create new records, and when creating a new record, the $RECORD values will not exist yet.
If you're passing date_of_visit in the create record link, maybe something like this could work?
<?php echo htmlencode($_REQUEST['date_of_visit'] ?? 'Ημερομηνία δεν είναι διαθέσιμη'); ?>
The ?? means "if the previous value isn't defined, use the next value".
Let me know if that helps, or more details about what you're trying to do.
interactivetools.com