diff --git a/wire/modules/Page/PageFrontEdit/PageFrontEdit.module b/wire/modules/Page/PageFrontEdit/PageFrontEdit.module
index 1b618d17..addbb05c 100644
--- a/wire/modules/Page/PageFrontEdit/PageFrontEdit.module
+++ b/wire/modules/Page/PageFrontEdit/PageFrontEdit.module
@@ -1170,27 +1170,31 @@ class PageFrontEdit extends WireData implements Module {
$inputfield = $this->getInputfield($page, $field);
$postName = $name;
+ // decode entities and strip tags?
+ $decodeAndStrip = false;
+
// jQuery HTML function entity encodes things like & to & even if they don't appear in the source
// so we determine if it's necessary to decode them here
if($inputfield instanceof InputfieldTextarea) {
if(wireInstanceOf($inputfield, 'InputfieldCKEditor')) {
- $decode = false;
+ // ok
} else if(wireInstanceOf($inputfield, 'InputfieldTinyMCE')) {
$postName = "Inputfield_$name";
- $decode = false;
} else if($field->get('contentType') >= FieldtypeTextarea::contentTypeHTML) {
- $decode = false;
+ // ok
} else {
- $decode = true;
+ // convert browser added div and break tags to newlines
+ $value = str_replace(array('
', '
', '
'), "\n", $value);
+ $value = str_replace(array('', '
'), array("\n", ""), $value);
+ $decodeAndStrip = true;
}
} else if($inputfield instanceof InputfieldText) {
- $decode = true;
- } else {
- $decode = false;
+ $decodeAndStrip = true;
}
- if($decode) {
+ if($decodeAndStrip) {
$value = $sanitizer->unentities($value);
+ $value = strip_tags($value);
}
$input->post->$postName = $value;
@@ -1294,6 +1298,7 @@ class PageFrontEdit extends WireData implements Module {
if(is_object($unformatted)) $unformatted = (string) $unformatted;
$purifyHTML = true;
+ $addBreaks = false;
if($field && $field->type instanceof FieldtypeTextarea) {
$contentType = (int) $field->get('contentType');
@@ -1301,7 +1306,11 @@ class PageFrontEdit extends WireData implements Module {
if($cls === 'InputfieldCKEditor' || $cls === 'InputfieldTinyMCE' || $contentType == 1 || $contentType == 2) {
// HTML is expected and allowed
$purifyHTML = false;
- }
+ } else if($cls === 'InputfieldTextarea') {
+ $textformatters = $field->get('textformatters');
+ if(in_array('TextformatterNewlineBR', $textformatters)) $addBreaks = true;
+ if(in_array('TextformatterMarkdownExtra', $textformatters)) $addBreaks = true;
+ }
}
if(is_string($unformatted) && $purifyHTML && (strpos($unformatted, '<') !== false || strpos($unformatted, '&') !== false)) {
@@ -1310,6 +1319,8 @@ class PageFrontEdit extends WireData implements Module {
$unformatted = $this->wire()->sanitizer->purify(trim($unformatted));
}
+ if($addBreaks) $unformatted = nl2br($unformatted);
+
return $unformatted;
}
}