NTS Forums

Please login or register.

Login with username, password and session length
 

News:

Welcome to the Newtek Technology Services Forum!


Author Topic: How to remove extra line breaks when inserting into mySQL field  (Read 2478 times)

Offline jbusha

  • he
  • Full Member
  • ****
  • Posts: 316
  • Karma: +3/-0
PDF with multiple form fields gets processed by a ColdFusion script. One of the fields is used for "Comments" and is configured as a "Multi-line" text field in PDF form. When processing by CF into mySQL (field type = text), extra line breaks get added each time a record is saved.

i.e.
This is line one.
This is line two.
This is line three.

is saved as

This is line one.

This is line two.

This is line three.

and each subsequent time it's saved, more linebreaks are added.

I've searched high and low for solution, found lots of iterations of ReReplace code, but now need to ask for help from my CT friends, as none are working as needed.

Thought this one would work:
<cfset request.CurrentComment = ReReplace(form.TEACHERCOMMENTS,"[#chr(10)#|#chr(13)#]+","#chr(10)##chr(13)##chr(10)##chr(13)#","ALL")> 
but it didn't

The one below worked *too well* . . . removing *all* new lines, running paragraphs together:
<cfset request.CurrentComment = ReReplace(form.TEACHERCOMMENTS,"[#chr(10)##chr(13)#]+","","ALL")>

Can't find the right combination of code to keep single returns.

Thanks in advance for any help . . . BTW, web server = Linux / Apache


Offline Cliff

  • he
  • Full Member
  • ****
  • Posts: 703
  • Karma: +7/-2
    • PathLabTalk
Re: How to remove extra line breaks when inserting into mySQL field
« Reply #1 on: March 28, 2013, 10:00:33 PM »
Are you using CKEditor?  The new version inserts a lot of line breaks.


If that is the issue you can add this to a config file, I got it from their site.



CKEDITOR.on( 'instanceReady', function( ev )
{
   var writer = ev.editor.dataProcessor.writer;
   // The character sequence to use for every indentation step.
   writer.indentationChars = '    ';
 
   var dtd = CKEDITOR.dtd;
   // Elements taken as an example are: block-level elements (div or p), list items (li, dd), and table elements (td, tbody).
   for ( var e in CKEDITOR.tools.extend( {}, dtd.$block, dtd.$listItem, dtd.$tableContent ) )
   {
      ev.editor.dataProcessor.writer.setRules( e, {
         // Indicates that an element creates indentation on line breaks that it contains.
         indent : false,
         // Inserts a line break before a tag.
         breakBeforeOpen : true,
         // Inserts a line break after a tag.
         breakAfterOpen : false,
         // Inserts a line break before the closing tag.
         breakBeforeClose : false,
         // Inserts a line break after the closing tag.
         breakAfterClose : true
      });
   }
 
   for ( var e in CKEDITOR.tools.extend( {}, dtd.$list, dtd.$listItem, dtd.$tableContent ) )
   {
      ev.editor.dataProcessor.writer.setRules( e, {         
         indent : true,
      });
   }
 
   // You can also apply the rules to a single element.
   ev.editor.dataProcessor.writer.setRules( 'table',
   {       
      indent : true
   });   
 
   ev.editor.dataProcessor.writer.setRules( 'form',
   {       
      indent : true
   });     
});
« Last Edit: March 28, 2013, 10:02:23 PM by Cliff »

Offline jbusha

  • he
  • Full Member
  • ****
  • Posts: 316
  • Karma: +3/-0
Re: How to remove extra line breaks when inserting into mySQL field
« Reply #2 on: March 29, 2013, 12:20:30 AM »
Thanks for the reply, Cliff.

No, I am not using CKeditor -- form field is "Multi-Line" text in an interactive PDF form that's populated by a mySQL database through CFquery/cfpdfformparam, etc.

Initial entry of form data works fine -- single returns dispaly as such next visit to form, but each subsequent "update" to the record adds another line under each "line break". So, single returns turn into double returns, double to triple, etc., etc. with each CFQUERY update.

If I go into form, and remove the extra lines and save, and return to the form, they're single spaced. But next time saved, with no changes to data, they'll be double spaced.

It's driving me crazy . . . the mySQL DB field type = text.

Offline jbusha

  • he
  • Full Member
  • ****
  • Posts: 316
  • Karma: +3/-0
Re: How to remove extra line breaks when inserting into mySQL field
« Reply #3 on: March 29, 2013, 01:05:56 AM »
You ever have one of those moments?

I think the solution to my problem has been found in a CF tag named "HTMLEditFormat" -- added it to form variable being entered in to mySQL and BINGO! No more extra linebreaks.

Thanks again, Cliff . . . leaving this post up in case anyone else experiences this problem.