Forums

Replace line-break by space in textarea

tico92 15 Jun, 2015
How to replace a line-break in the textarea by a <br>.
When the table is imported in Excel, I want all the line-breaks in the textarea be replaced by a space.
Otherwise all content will be spread over different rows in Excel.

I could manage in the older versions of CF but wondering how to do it in CF5.

Thanks in advance,

Tico
tico92 15 Jun, 2015
Hi Bob,

This is not exactly what I meant.
I will try to explain more.

When I import the CSV export into Excel the textarea is the problem. Whenever the subscriber uses an 'Enter' (carriage return) in the textarea it shows in Excel in more than 1 cell. What I would like is the whole textarea text in 1 cell.

So instead of:
thanks.
greetings.

I would like to see:
thanks. greetings.

Can you help me?

Tico
GreyHead 16 Jun, 2015
Hi Tico,

The post I linked to answers this question How to replace a line-break in the textarea by a <br>.

To use spaces instead I'd suggest that you add a couple of extra lines. One to replace <br /> with a space and the second to replace a double space with a single space to tidy up a bit.

Though IMHO you are better to stick with the <br />

Bob
tico92 13 Oct, 2015
Hi Bob,

still I am searching for a way to get rid of the line breaks (carriage return) in the text area.
In your CFv4 CSV Export (GH) action you added :

" Added option to remove carriage return and newline characters for Excel exports."

that worked perfectly in CFv4 and that's what I am looking for in CFv5.

I already set a maxlength of characters but people keep on using the carriage return and it messes up the excel report.

Can you help me please,
thanks,

Tico
GreyHead 13 Oct, 2015
Answer
Hi Tico,

That option is still there in the CFv5 version of my action - PM me if you want to try a copy,

With the standard action I'd use a Custom Code action before the Export action and convert the textarea data.
<?php
$textareas = array(
  'textarea1',
  . . .
);
foreach( $textareas as $t ) {
  $form->data[$t] = nl2br($form->data[$t]);
}
?>
Add the names of the textareas you want to edit in the array.

You can also do this in the form On Submit event before the data is saved if that helps.

Bob
tico92 14 Oct, 2015
Hi Bob,

thanks and it works great.

Problem solved for me.

Tico
This topic is locked and no more replies can be posted.