Jump to content

Strange behavior while importing text data in a PW textarea with API


Recommended Posts

Posted

Hello Forum,

Yet another question.  I'm importing data from an old database structure into Processwire.
But when I import following data into a textarea (the standard Body one) then I get a lot of <p>&nbsp;</p> for some odd reason.
Someone has a clue?

I have used several approaches.

// this
$text = nl2br($r['textEN']);
// but also this
$text = $sanitizer->textarea($r['textEN'],array('multiLine'=>false,'newlineReplacement'=>'<br>','stripTags'=>false)); // 
// no difference
                    



The data from a text field in mysql:

<table border="1" cellspacing="0" cellpadding="0">
	<tbody><tr>
		<td width="403"><p><strong><em>Results</em></strong></p></td>
		<td width="95"><p align="right"><strong>30.06.2017</strong></p></td>
		<td width="96"><p align="right"><strong>30.06.2016</strong></p></td>
	</tr>
	<tr>
		<td><p>Operating result</p></td>
		<td><p align="right">11,402</p></td>
		<td width="96"><p align="right">10,163</p></td>
	</tr>
	<tr>
		<td><p>Net result of the year</p></td>
		<td><p align="right">3,853</p></td>
		<td width="96"><p align="right">2,688</p></td>
	</tr>
	<tr>
		<td><p>Share of the group in the net result of the year</p></td>
		<td><p align="right">3,888</p></td>
		<td width="96"><p align="right">2,689</p></td>
	</tr>
	<tr>
		<td><p><strong><em>Balance sheet</em></strong></p></td>
		<td><p align="right"><strong>30.06.2017</strong></p></td>
		<td width="96"><p align="right"><strong>31.12.2016</strong></p></td>
	</tr>
	<tr>
		<td><p>Total assets</p></td>
		<td><p align="right">641,120</p></td>
		<td width="96"><p align="right">605,547</p></td>
	</tr>
	<tr>
		<td><p>Cash and cash equivalents</p></td>
		<td><p align="right">17,263</p></td>
		<td width="96"><p align="right">15,273</p></td>
	</tr>
	<tr>
		<td><p>Net financial debt (-)</p></td>
		<td><p align="right">360,423</p></td>
		<td width="96"><p align="right">341,263</p></td>
	</tr>
	<tr>
		<td><p>Total equity</p></td>
		<td><p align="right">214,257</p></td>
		<td width="96"><p align="right">210,408</p></td>
	</tr>
</tbody></table>

 

The result in the textarea Body (source view):

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<table border="1" cellpadding="0" cellspacing="0">
	<tbody>
		<tr>
			<td>
			<p><strong><em>Results</em></strong></p>
			</td>
			<td>
			<p><strong>30.06.2017</strong></p>
			</td>
			<td>
			<p><strong>30.06.2016</strong></p>
			</td>
		</tr>
		<tr>
			<td>
			<p>Operating result</p>
			</td>
			<td>
			<p>11,402</p>
			</td>
			<td>
			<p>10,163</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>Net result of the year</p>
			</td>
			<td>
			<p>3,853</p>
			</td>
			<td>
			<p>2,688</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>Share of the group in the net result of the year</p>
			</td>
			<td>
			<p>3,888</p>
			</td>
			<td>
			<p>2,689</p>
			</td>
		</tr>
		<tr>
			<td>
			<p><strong><em>Balance sheet</em></strong></p>
			</td>
			<td>
			<p><strong>30.06.2017</strong></p>
			</td>
			<td>
			<p><strong>31.12.2016</strong></p>
			</td>
		</tr>
		<tr>
			<td>
			<p>Total assets</p>
			</td>
			<td>
			<p>641,120</p>
			</td>
			<td>
			<p>605,547</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>Cash and cash equivalents</p>
			</td>
			<td>
			<p>17,263</p>
			</td>
			<td>
			<p>15,273</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>Net financial debt (-)</p>
			</td>
			<td>
			<p>360,423</p>
			</td>
			<td>
			<p>341,263</p>
			</td>
		</tr>
		<tr>
			<td>
			<p>Total equity</p>
			</td>
			<td>
			<p>214,257</p>
			</td>
			<td>
			<p>210,408</p>
			</td>
		</tr>
	</tbody>
</table>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

PS: sorry for the long markup/post...  ?

Posted (edited)

I'm pretty sure it's CKEditor doing that and not sanitizer->textarea();

Maybe this will help?

 

Edited by kongondo
  • Like 2
Posted
On 9/26/2018 at 6:28 AM, KarlvonKarton said:

I have used several approaches.


// this
$text = nl2br($r['textEN']);
// but also this
$text = $sanitizer->textarea($r['textEN'],array('multiLine'=>false,'newlineReplacement'=>'<br>','stripTags'=>false)); // 
// no difference
                    

 

I think the problem here is that you are replacing newlines with <br>, but that doesn't make sense for the content you are importing. If your content consists of markup then you don't want newlines to become <br>s because the newlines exist in the markup just for code readablity and aren't something that should result in new HTML tags in the saved field value.

If you set the field value directly from $r['textEN'] then it should work.

  • Like 2

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...