Multiline Text Field - Lines Run Together

hpinson 11 Sep, 2007
Hi. I can't seem to get Chronoforms to render newline breaks from the form to the email and into the database. In php I would do this using the nl2br directive. Any suggestions on how to render line breaks in Chronoforms output?
GreyHead 11 Sep, 2007
Hi hpinson,

Just checking, these are line breaks in the data fields - in a textarea for instance. I don't think that ChronoForms does any processing at present. I guess that Max might add something in a future version.

You could add some php processing yourself in the OnSubmit - before email field and see if that gives the reault you want?

Bob<br><br>Post edited by: GreyHead, at: 2007/09/11 18:30
hpinson 11 Sep, 2007
Yes, adding this to the Autogenerated setQuery added the line breaks to the output from the multiline textentry box:
setQuery(".... 
'".$_POST[nl2br('mailing_address_international')]."' , 
...


Thanks.

Edited to add code tags.<br><br>Post edited by: GreyHead, at: 2007/09/11 18:31
andrew222 24 Oct, 2007
Do you mind if I jump in on this thread and ask where the code is added?

I too revieve emails with just a block of text and it would be lice to have some line breaks etc to make things tidy.

I'm looking at the section

On Submit code - before sending email:

but don't understand what php to put in there :blink:

Look forward to any advice,

Thanks

Andrew
Max_admin 24 Oct, 2007
Hi Andrew,

hpinson edited the code generated at the autogenerated field!!

Sincerely,

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
isaac_ho 24 Oct, 2007
I have the same problem.

for example: i type the following text into the textarea.
Line One
Line Two
Line Three
Line Four

And I receive the email like this:
Line One Line Two Line Three Line Four

In the email source code, the text have line breaks:

...
<td>Line One
Line Two
Line Three
Line Four</td>
...

Who knows how to add a "<br />" tag after each line?
Max_admin 24 Oct, 2007
Hi,

We can hack chronocontact.php, at line 209, and assuming your textarea name is textarea1, put this code :


$_POST['textarea1'] = str_replace("\n","<br>",$_POST['textarea1']);
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
isaac_ho 25 Oct, 2007

Hi Andrew,

hpinson edited the code generated at the autogenerated field!!

Sincerely,

Max



Dear Admin,

It only renders textarea data with <br /> tag in the database, but not email.
isaac_ho 25 Oct, 2007

Hi,

We can hack chronocontact.php, at line 209, and assuming your textarea name is textarea1, put this code :


$_POST['textarea1'] = str_replace("\n","<br>",$_POST['textarea1']);



Dear Max and All,
I put this code in the "Form Code" > "On Submit code - before sending email:", and it works

the "textarea1" is your textarea field name


<?php
$_POST['textarea1'] = str_replace("\n","<br>",$_POST['textarea1']);
?>
<br><br>Post edited by: isaac_ho, at: 2007/10/25 05:16
Max_admin 25 Oct, 2007
Great!!🙂

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
andrew222 26 Oct, 2007
Excellent!!

Thanks very much for sorting that code out. Got mine working now after changing line 209 and then adding the code that isaac_ho supplied.

:cheer:

All the best

Andrew
isaac_ho 29 Oct, 2007
...

I put this code in the "Form Code" > "On Submit code - before sending email:", and it works

the "textarea1" is your textarea field name


<?php
$_POST['textarea1'] = str_replace("\n","<br>",$_POST['textarea1']);
?>
<br><br>Post edited by: isaac_ho, at: 2007/10/25 05:16[/quote]

sorry! i make a mistake. in fact, place the above code into "Form Code" > "On Submit code - before sending email:" doesn't work.
isaac_ho 29 Oct, 2007

Hi,

We can hack chronocontact.php, at line 209, and assuming your textarea name is textarea1, put this code :


$_POST['textarea1'] = str_replace("\n","<br>",$_POST['textarea1']);



Dear Admin,

Is there any way to do the same thing in "On Submit code - before sending email:" instead of hacking file "chronocontact.php"?
Max_admin 29 Oct, 2007
Hi Issac,

You mentioned in another thread that this already works with you ?!!!🙂

You can try this code in the on submit before email and see :
$html_message = str_replace("\n","<br>",$html_message);
Cheers

Max<br><br>Post edited by: GreyHead, at: 2008/01/04 12:19
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
isaac_ho 30 Oct, 2007

Hi Issac,

You mentioned in another thread that this already works with you ?!!!🙂

You can try this code in the on submit before email and see :


$html_message = str_replace("\n","<br>",$html_message);



Cheers

Max



Dear Max,

i'm trying.<br><br>Post edited by: isaac_ho, at: 2007/10/30 04:29
isaac_ho 30 Oct, 2007

Hi Issac,

You mentioned in another thread that this already works with you ?!!!🙂

You can try this code in the on submit before email and see :

$html_message = str_replace("\n","<br>",$html_message);
Cheers

Max



Dear Max,

Your code only works partially, because <br> is added into every line of the email HTML source code, looks like:

Subject: Form A - Show Directory Listing
Message-ID: <7dfed174fba4637b10297b3bdada7a45@penton.office.anywhere.localnet>
X-Priority: 3
X-Mailer: PHPMailer [version 1.73]
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/html; charset="utf-8"

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<br>						  <html>
<br>							  <head>
<br>								  <title></title>
<br>								  <base href="http://penton.office.anywhere.localnet/" />
<br>								  <style type="text/css">
<br>								  
<br>								  </style>
<br>							  </head>
<br>							  <body><table cellpadding='0' cellspacing='0' border='0' width='100%'><tr height='10'>
<br>	                   <td width='40%' class='tablecell1'>exhibitor</td>
<br>	                   <td width='60%' class='tablecell2'></td>
<br>	                   </tr><tr height='10'>
<br>	                   <td width='40%' class='tablecell1'>exhibitor_email</td>
<br>	                   <td width='60%' class='tablecell2'></td>
<br>	                   </tr><tr height='10'>
<br>	                   <td width='40%' class='tablecell1'>misc_other</td>
<br>	                   <td width='60%' class='tablecell2'></td>
<br>	                   </tr></table></body></html>
<br><br>Post edited by: GreyHead, at: 2008/01/04 12:18
Max_admin 30 Oct, 2007
Hmmm, I agree, then a hack must be done!!😉

Cheers

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
discdemo 04 Jan, 2008
Can anyone add to the above with specifics on what you would do if you had 3 textareas to add breaks to?

My email results still come without word wrap, but I haven't edited 209 yet, only added the code for before email sends.

Also, can anyone clarify or confirm that a break will happen, based upon the the text box character width? Such as, i type straight across without stopping; the text box pishes down to next line. WIll that cause a break?

My goal is to get the email results for that text area in paragraph form.

Thanks! -jz
GreyHead 04 Jan, 2008
Hi jz,

Not tested but try this in the email template.
<?php
$textareas = array('textarea1', 'textarea2', 'textarea3');
foreach ($textareas as $textarea) {
  $fields['$textarea'] = nl2br($fields['$textarea']);
  if ( strlen($fields['$textarea']) > 75 ) {
    $fields['$textarea'] = wordwrap($fields['$textarea'], 75, '<br />/n');
  }
}
?>
Not tested so may be buggy! But in theory should replace all '/n's with '<br />' and then wordwrap the test at 75 characters. You may well need to tweak the settings to get exactly what you want.

And No, the textarea width does not carry into the stored text. Only breaks that you type will be saved - but the wordwrap should fix that for you.

Bob<br><br>Post edited by: GreyHead, at: 2008/01/04 17:52
discdemo 04 Jan, 2008
Thanks for the suggestion, Bob.

Forgive me, but I'm not clear on the "email template". I have used the Form Code...where do I go from there?

Thanks, again. -jz
GreyHead 04 Jan, 2008
Hi jz,

No problem.

The place to set up a custom email format is the Email template at the foot of teh Form Code tab. You'll also need to set 'In which format to send the results email:' to My Template on the General Tab.

The Email template takes a combination of php & html to format the email. You include field results by adding {fieldname} where you want them to appear.

Put the code snippet below at the beginning of the Email template and it will re-format the results for the textareas that you specify in the $textareas array line.

What you do with the rest of the email is up to you. You could simply reproduce the standard table layout, or use some html to give the fields neat headings.

Bob
discdemo 04 Jan, 2008
Appreciate the training, Bob.

I went in and just adjusted the fist text area to match my first text area:
<?php
$textareas = array('about_us', 'textarea2', 'textarea3');
foreach ($textareas as $textarea) {
  $fields['$textarea'] = nl2br($fields['$textarea']);
  if ( strlen($fields['$textarea']) > 75 ) {
    $fields['$textarea'] = wordwrap($fields['$textarea'], 75, '<br />/n');
  }
}
?>
My results are the same. Does that look ok and...do I need to do anything to that line 209? Is that related, or no.

Thx. -jz<br><br>Post edited by: GreyHead, at: 2008/01/04 18:27
GreyHead 04 Jan, 2008
Hi jz,

Sorry, I've made a booboo . . . take the quotes out of $fields[$textarea] in five places please.

And no - if this works - it will replace the 209 hack.

Bob
discdemo 05 Jan, 2008
I edited the last line...was that the wrong one? I had no joy.

Sorry, couldn't decipher.
<?php
$textareas = array('about_us', 'textarea2', 'textarea3');
foreach ($textareas as $textarea) {
  $fields['$textarea'] = nl2br($fields['$textarea']);
  if ( strlen($fields['$textarea']) > 75 ) {
    $fields[$textarea] = wordwrap($fields[$textarea], 75, <br />/n');
  }
}
?>
GreyHead 05 Jan, 2008
Hi dz,

No all five of them were wrong:
<?php
$textareas = array('about_us', 'textarea2', 'textarea3');
foreach ($textareas as $textarea) {
  $fields[$textarea] = nl2br($fields[$textarea]);
  if ( strlen($fields[$textarea']) > 75 ) {
    $fields[$textarea] = wordwrap($fields[$textarea], 75, <br />/n');
  }
}
?>
Try this version

Bob
discdemo 05 Jan, 2008
hmm, no joy. i then went back and removed anything i had placed in line 209 earlier, just to be safe.

also, i think you recall, but just to clarify...i'm not manually entering any breaks. i think we're hoping the word wrap part works, right?

anyhow, sorry for the hassle. no joy as of yet.

thx. -jz
GreyHead 05 Jan, 2008
Hi jz,

Hmmm . . . Please will you click the Backup Form icon and send me a copy of your form (email in my sig). I'll have a go later at trying the code on my setup, better to do it on your form than make one up though.

Bob
discdemo 05 Jan, 2008
Sure...thanks Bob. Very kind of you.

thx. -jz [file name=Intake.cfbak size=14116]http://www.chronoengine.com/components/com_fireboard/uploaded/files/Intake.cfbak[/file]
GreyHead 05 Jan, 2008
Hi jz,

Here's the code to put in the Email template box
<?php
$textareas = array('about_us', 'locations', 'contact_us', 'services');
foreach ($textareas as $textarea) {
  $fields[$textarea] = nl2br($fields[$textarea]);
  if ( strlen($fields[$textarea]) > 75 ) {
    $fields[$textarea] = wordwrap($fields[$textarea], 75, "<br />"«»);
  }
}
?>
<table width="100%" cellspacing="0" cellpadding="0" border="0" >
<tbody>
<tr height="10" >
<td class="tablecell1" width="40%" >lockup1</td>
<td class="tablecell2" width="60%" >{lockup1}</td>
</tr>
<tr height="10" >
<td class="tablecell1" width="40%" >lockup2</td>
<td class="tablecell2" width="60%" >{lockup2}</td>
</tr>
<tr height="10" >
<td class="tablecell1" width="40%" >lockup3</td>
<td class="tablecell2" width="60%" >{lockup3}</td>
</tr>
<tr height="10" >
<td class="tablecell1" width="40%" >dpm</td>
<td class="tablecell2" width="60%" >{dpm}</td>
</tr>
<tr height="10" >
<td class="tablecell1" width="40%" >mt</td>
<td class="tablecell2" width="60%" >{mt}</td>
</tr>
<tr height="10" >
<td class="tablecell1" width="40%" >reflex</td>
<td class="tablecell2" width="60%" >{reflex}</td>
</tr>
<tr height="10" >
<td class="tablecell1" width="40%" >pedicure</td>
<td class="tablecell2" width="60%" >{pedicure}</td>
</tr>
<tr height="10" >
<td class="tablecell1" width="40%" >email</td>
<td class="tablecell2" width="60%" >{email}</td>
</tr>
<tr height="10" >
<td class="tablecell1" width="40%" >worldtag</td>
<td class="tablecell2" width="60%" >{worldtag}</td>
</tr>
<tr height="10" >
<td class="tablecell1" width="40%" >steptag</td>
<td class="tablecell2" width="60%" >{steptag}</td>
</tr>
<tr height="10" >
<td class="tablecell1" width="40%" >needsdomain</td>
<td class="tablecell2" width="60%" >{needsdomain}</td>
</tr>
<tr height="10" >
<td class="tablecell1" width="40%" >no_need_domain</td>
<td class="tablecell2" width="60%" >{no_need_domain}</td>
</tr>
<tr height="10" >
<td class="tablecell1" width="40%" >domain1</td>
<td class="tablecell2" width="60%" >{domain1}</td>
</tr>
<tr height="10" >
<td class="tablecell1" width="40%" >domain2</td>
<td class="tablecell2" width="60%" >{domain2}</td>
</tr>
<tr height="10" >
<td class="tablecell1" width="40%" >domain3</td>
<td class="tablecell2" width="60%" >{domain3}</td>
</tr>

<tr height="10" >
<td class="tablecell1" width="40%" >subdomain</td>
<td class="tablecell2" width="60%" />{subdomain}</td>
</tr>
<tr height="10" >
<td class="tablecell1" width="40%" >no_subdomain</td>
<td class="tablecell2" width="60%" />{no_subdomain}</td>
</tr>
<tr height="10" >
<td class="tablecell1" width="40%" >needs_hosting</td>
<td class="tablecell2" width="60%" />{needs_hosting}</td>
</tr>
<tr height="10" >
<td class="tablecell1" width="40%" >no_hosting_needed</td>
<td class="tablecell2" width="60%" />{no_hosting_needed}</td>
</tr>
<tr height="10" >
<td class="tablecell1" width="40%" >about_us</td>
<td class="tablecell2" width="60%" >{about_us}</td>
</tr>
<tr height="10" >
<td class="tablecell1" width="40%" >locations</td>
<td class="tablecell2" width="60%" >{locations}</td>
</tr>
<tr height="10" >
<td class="tablecell1" width="40%" >contact_us</td>
<td class="tablecell2" width="60%" >{contact_us}</td>
</tr>
<tr height="10" >
<td class="tablecell1" width="40%" >services</td>
<td class="tablecell2" width="60%" >{services}</td>
</tr>
</tbody>
</table>
It's just a table to display the results (I think I may have missed on field somewhere so you'll need to check.

Also, you need to remove the <form> tags from your form code - as ChronoForms will add its own. (I'm not sure that the webbot validation will work here.)

And, lastly, set the 'In which format to send the results email:' box to My template.

Note: If you want to use debug to see the results you'll need to temporarily remove the Redirect URL form the Form URLs page.

Bob
nosins 22 Apr, 2008
Hi there,

I was following this thread to resolve what I believe to be the same problem. I'm not emailing my code anywhere - just storing in the db. So, my way of accessing the data is through your admin interface. However, the data entered into the textarea is displayed without any returns or breaks... hence why I found this thread.

I added your suggested php code to my HTML form code (editing for my own fields, of course) and receive the following error when loading the form in a browser to test:

Notice: Undefined variable: fields

Any thoughts?

Thanks,

Nick.
GreyHead 22 Apr, 2008
Hi nosins,

That's a PHP warning message, you can usually remove them by setting Error Notices to System Default in Site Configuration.

Can you tell me what the rest of the message says - it should have a file name and a line number or two.

Thanks

Bob
nosins 22 Apr, 2008
Hi Bob,

Thanks for the reply. Here's the full error:

Notice: Undefined variable: fields in ...root/components/com_chronocontact/chronocontact.html.php(83) : eval()'d code on line 4

Thanks again,

Nick.
GreyHead 22 Apr, 2008
Hi Nick,

The warning appears to be triggered by Line 4 of your HTML form code, please can you post the first dozen lines here.

Thanks

Bob<br><br>Post edited by: GreyHead, at: 2008/04/22 00:24
nosins 22 Apr, 2008
Hi Bob,

Here's the part of the code that it's referring too... just an edited version of what I got from this forum🙂
<?php
$textareas = array('qquestion');
foreach ($textareas as $textarea) {
  $fields[$textarea] = nl2br($fields[$textarea]);
  if ( strlen($fields[$textarea]) > 75 ) {
    $fields[$textarea] = wordwrap($fields[$textarea], 75, "<br />");
  }
}
?>
Thanks in advance for the help!

Nick.
GreyHead 22 Apr, 2008
Hi Nick,

Make that
<?php
$fields = array();  // add this line
$textareas = array('qquestion');
foreach ($textareas as $textarea) {
  $fields[$textarea] = nl2br($fields[$textarea]);
  if ( strlen($fields[$textarea]) > 75 ) {
    $fields[$textarea] = wordwrap($fields[$textarea], 75, "<br />");
  }
}
?>
and it should go away. The message is a PHP warning that a variable is being used without being declared first. In this case it's harmless but looks messy. On a production site it's better to turn these warnings off.

Bob
nosins 22 Apr, 2008
Thanks Bob.

It seems now I'm getting a different error though...

Notice: Undefined index: qquestion in root/components/com_chronocontact/chronocontact.html.php(83) : eval()'d code on line 5

We're working on a Dev site ...just getting things ready🙂

Thanks again, Nick.
GreyHead 22 Apr, 2008
Hi Nick,

That's weird, looks like a punctuation error somewhere. Can you take a Form Backup and mail it to me at the address in my sig.

Thanks

Bob
Roudolfa 24 May, 2009
Hi!
I am trying to deal with the multiline issue as well and don't seem to have any luck yet.
After reading the previous relevant posts and searching for nl2br, I concluded that I should enter the following code in the "On Submit code - before sending email" field at the "Form Code" tab of my form, but it doesn't seem to work:


<?php
$fields = array(); 
$textareas = array('pres_desc', 'prep_desc', 'app_desc', 'exer_desc');
foreach ($textareas as $textarea) {
  $fields[$textarea] = nl2br($fields[$textarea]);
  if ( strlen($fields[$textarea]) > 75 ) {
    $fields[$textarea] = wordwrap($fields[$textarea], 75, "<br />");
  }
}
?>


I receive no error messages, it simply doesn't work, after filling in a new form the lines still appear together.
I am not using e-mails, I am just saving the submitted data in a database table and use Chronoconnectivity to display them.
Am I missing something here?

Thanks in advance,
Emily.
GreyHead 24 May, 2009
Hi Emily,

This is code from a year ago for an older version of ChronoForms. The Logic is still correct but I don't see that this is picking up the submitted information or putting the revised areas anywhere useful. Please try this variant.
<?php
$textareas = array('about_us', 'textarea2', 'textarea3');
foreach ($textareas as $textarea) {
  $text_data = JRequest::getVar($textarea, '', 'post');
  $text_data = nl2br($text_data);
  if ( strlen($text_data) > 75 ) {
    $text_data = wordwrap($text_data, 75, <br />/n');
  }
  JRequest::setVar($textarea, $text_data, 'post');
}
?>

Bob
Roudolfa 24 May, 2009
Hi Bob,
thanks a lot for the prompt reply, I really appreciate it!

Unfortunately I had no luck with the new version either...
(I did change the names in the textarea array to match the fields in my form)

I put the following text in the form:

aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa

bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb

ccc ccc ccc ccc ccc ccc ccc ccc



and I receive:

aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb bbb ccc ccc ccc ccc ccc ccc ccc ccc




In fact, I don't really mind about the wordwrap, as long as the user defined line changes are maintained.
Any thoughts?
Max_admin 24 May, 2009
Hi Emily,

This is fixed in RC5.1, you may contact me through the contact us page to get a pre release version!

Cheers
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.