Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to save user input linebreak to database. (jQuery/php/mysql)
    text
    copied!<p>The question is: <strong>How to save user input linebreak to database. (jQuery/php/mysql)</strong></p> <p>I have a paragraph which is editable by the user.</p> <pre><code>&lt;p contenteditable="true" id="forbiddenField"&gt;Text&lt;/p&gt; </code></pre> <p>When I retrieve data from db with this:</p> <pre><code>&lt;p contenteditable="true" id="forbiddenField"&gt;&lt;?php echo nl2br($forbidden); ?&gt;&lt;/p&gt; </code></pre> <p>and that works great.</p> <p>onblur (.blur) will activate a jQuery script which will send the new edited data to a database. </p> <pre><code>$("#forbiddenField").blur(function(){ var whatIsNowForbidden = encodeURI($("#forbiddenField").text()); $.ajax({ type: "POST", url: "updateForbidden.php", data: "forbiddenStuff="+ whatIsNowForbidden, success: function(){ } }); }); </code></pre> <p><strong>Problem:</strong> If the user inserts new data, with linebreaks, then the linebreaks are not added to the data in the database, only the content is added.</p> <p>I tried this among other things: var whatIsNowForbidden = encodeURI($("#forbiddenField").text());</p> <p>I looked at theese places for answers: <a href="https://stackoverflow.com/questions/5999792/new-line-in-textarea-to-be-converted-to-br">New Line in Textarea to be converted to &lt;br/&gt;</a> <a href="http://www.w3schools.com/tags/ref_urlencode.asp" rel="nofollow noreferrer">http://www.w3schools.com/tags/ref_urlencode.asp</a> <a href="https://stackoverflow.com/questions/3902451/is-replacing-a-line-break-utf-8-safe">Is replacing a line break UTF-8 safe?</a> <a href="https://stackoverflow.com/questions/6631270/how-to-escape-input-but-save-unescaped-into-the-database">how to escape input but save unescaped into the database</a> <a href="https://stackoverflow.com/questions/3242211/how-to-recognize-every-linebreak">How to recognize every linebreak?</a></p> <p>I can't get it to work. All input and hints are much appreciated!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload