Save formatted text to database and retrieve it back 'as is' like a formatted string

前端 未结 1 1588
北恋
北恋 2021-01-26 00:15

I am embedding tinymce [http://www.tinymce.com/] in twitter bootstrap form , so that user can input formatted text which I can persist to a postgres database.

The probl

1条回答
  •  [愿得一人]
    2021-01-26 00:34

    Basically, the simplest way to do this is through adding a hidden field to your form and a click event handler on the submit button.

    so, create a hidden input on your format, with the name "message_formatted" (since I imagine your corresponding field in your model is called message_formatted), and change the name of your textarea to something else, as that will no longer be important.

    using jQuery:

    $('#signup input[type=submit]').click(function(e){
      $('input[name=message_formatted]').val(tinyMCE.get('content id').getContent());
    });
    

    In terms of where to add the javascript, that's up to you. It's best to place it in a javascripts directory (it's unclear whether you're using Rails and the asset pipeline or not). If you want to just add the javascript inline within this haml page, place the above within the content_for :javascript do at the bottom of your page

    content_for :javascript do
      // enter the javascript from above here
    

    0 讨论(0)
提交回复
热议问题