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

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.

Dave Edis - Senior Developer
interactivetools.com