1

I have set up a guest entries form that receives data from the textarea snippet below and saves it into a rich text field.

<textarea name="fields[comment]" placeholder="Join the discussion..."></textarea>

When I view the entry on the front-end there is no formatting, but on the backend there is formatting. Then when I save the entry on the back-end, suddenly there is formatting on the front-end.

Is there anyway to bypass having to re-save the entry to get the desired formatting?

3
  • Is it a Rich Text field?
    – Ryan Shrum
    Commented Feb 5, 2015 at 19:17
  • Yes. And when I view source in Redactor I can see paragraph tags that start to show up after I save the entry again. Commented Feb 5, 2015 at 19:27
  • 1
    Without using a JavaScript parser, not sure you'd be able to achieve what you're looking for. Unless of course you want to allow Redactor on the front-end. craftcms.stackexchange.com/questions/4225/…
    – Ryan Shrum
    Commented Feb 5, 2015 at 19:57

1 Answer 1

2

RichText fields make use of the Redactor plugin library, which if I understand correctly, essentially parses line-breaks and wraps lines in properly formatted html <p> tags via javascript. However, when you save from the front-end, it doesn't have a chance yet to parse the data. Only when you view the data on the back-end and re-save does redactor get a chance to do it's thing.

  • You could use redactor on the front-end, although this is not recommended for various reasons as described here.

  • Or you could change the fieldtype to a regular textField and wrap everything in a <pre> tag in your template. <pre>{{ entry.myTextField }}</pre>

  • Or you could parse the string yourself via javascript before submitting it, wrapping your own <p> tags (hopefully it won't get double encoded).

There might be other options as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.