I note a lot of questions asked about converting HTML characters such as greater/lesser than, ampersand, etc. to HTML entities, but I am not concerned with that. What I am having an issue with is:
JavaScript/Ajax code that passes values from an INPUT control that have character such as â to a PHP program -- in the PHP program I am storing the data using
mysqli_real_escape_string()
which if I weren't using Javascript/Ajax would do the trick.It appears that before it gets to the PHP code, it is converted to something odd (two symbols) in the process (I fixed the data already, so can't tell you the exact two symbols, and doubt it is that important). I would like to have this converted to
â
which is the correct HTML Entity. However, I cannot find an answer out on the web that deals with this ...
I don't need every character in a string converted to HTML entities, just the higher end letters with diacriticals (accent symbols and such). I am hoping someone has a function for JavaScript that does this, but so far what I'm seeing searching the web does way too much (converting every character in a string to the HTML entity is not space efficient when storing it in a table).
JavaScript/Ajax code to obtain and pass data:
function remembrance_save()
{
// first thing, clear out the message div used for this (if there's anything there):
document.getElementById("remembrance_message").innerHTML = "";
// from here we need to get the contents of all the various entry areas, and pass them
// off to a PHP file and save the data ...
// copy award data to session object by use of ajax/php:
var namecode = document.getElementById("namecode").value;
// get value from TinyMCE ... not the DOM for JavaScript:
var remembrance = tinymce.get('remembrance').getContent();
var cl = document.getElementById("commentor_link").value;
var cn = document.getElementById("commentor_name").value;
$.ajax
({
type: "POST",
url: "<?php echo $History_html_RootPath; ?>Who/AjaxCalls/remembrance_save.php",
data: { 'namecode' : namecode,
'remembrance' : remembrance,
'commentor_link' : cl,
'commentor_name' : cn },
//cache: false,
success: function(data)
{
// need to see if we have an error, if so, display it, otherwise,
// we should hopefully have success ...
if ( data.toLowerCase().includes( "error" ) )
{
var errormsg = "<div class='alert alert-danger'>"+data+"</div>";
document.getElementById("remembrance_message").innerHTML = errormsg;
return;
}
else
{
// success!
// change the message, and then clear out the values:
var message = "<div class='alert alert-success'>";
message += data;
message += "</div>";
document.getElementById("remembrance_message").innerHTML = message;
// clear out values:
// the remembrance editor takes two, because TinyMCE (editor)
// stores the values its own way
document.getElementById("remembrance").value = "";
tinymce.get('remembrance').setContent( "" );
// the other two
document.getElementById("commentor_link").value = "0";
document.getElementById("commentor_name").value = "";
return;
}
} // end success
}); // end ajax call
}; // end function remembrance_save()