Note that there are some explanatory texts on larger screens.

plurals
  1. POserialize() does not work with apostrophe
    text
    copied!<p>I'm having some trouble with my code below when trying to submit a form dynamically. The serialize() function works great except when there is an apostrophe in a form field. </p> <p>From the other places I've looked online, it appears serialize() is supposed to take care of that. For some odd reason, it fails on me.</p> <p>Here is my code:</p> <pre><code>//Submit Edit Facility form data $("#Facility_Edit").click(function() { var dataString = $("#edit_facility").serialize(); alert (dataString); //return false; $.ajax({ type: "POST", url: "process.php", data: dataString, success: function() { $('#submitresults').html("&lt;div id='message' class='alert-message fade in' data-alert='alert'&gt;&lt;/div&gt;"); $('#message').html("&lt;b&gt;Account has been edited successfully!&lt;/b&gt;") .append("&lt;p&gt;If you would like to make more changes, please do so below. Otherwise, please click &lt;a href='facility.php?facility_id=&lt;?php echo $facility_id;?&gt;'&gt;here to view the account.&lt;/p&gt;") .hide() .fadeIn(1500, function() { $('#message').prepend("&lt;a class='close' href='#'&gt;&amp;times;&lt;/a&gt;"); setTimeout('window.location="facility.php?facility_id=&lt;?php echo $facility_id;?&gt;&amp;action=edit"', 3000) }); } }); return false; }); </code></pre> <p>This is the output I receive with an apostrophe:</p> <pre><code>Facility_Name=Coeur+d'Alene+Homes+&amp;Facility_Type=Assisted+Living+Facility&amp; Facility_Address=624+W+Harrison&amp;Facility_Beds=&amp;Facility_City=Coeur+d'Alene&amp; Facility_State=ID&amp;Facility_Zip=83814&amp;Facility_OC=Tambra&amp;Facility_Phone=&amp;Facility_HCC=&amp; Facility_Fax=&amp;Facility_Team=CDA&amp;Facility_DC=&amp;facility_facilitypreference_status=&amp; Facility_ID=1305&amp;Submit_Type=editfacility </code></pre> <p>Notice, when the apostrophe's are removed, the code works great and submits properly. How can I fix this?</p> <p><strong>EDIT: Added PHP side code</strong></p> <pre><code>$facility_name = htmlspecialchars(trim($_POST['Facility_Name'])); $facility_type = htmlspecialchars(trim($_POST['Facility_Type'])); $facility_address = htmlspecialchars(trim($_POST['Facility_Address'])); $facility_zip = htmlspecialchars(trim($_POST['Facility_Zip'])); $facility_oc = htmlspecialchars(trim($_POST['Facility_OC'])); $facility_hcc = htmlspecialchars(trim($_POST['Facility_HCC'])); $facility_phone = htmlspecialchars(trim($_POST['Facility_Phone'])); $facility_beds = htmlspecialchars(trim($_POST['Facility_Beds'])); $facility_fax = htmlspecialchars(trim($_POST['Facility_Fax'])); $facility_dc = htmlspecialchars(trim($_POST['Facility_DC'])); </code></pre> <p>I've also tried: </p> <pre><code>$facility_name = htmlspecialchars(addslashes(trim($_POST['Facility_Name']))); $facility_type = htmlspecialchars(trim($_POST['Facility_Type'])); $facility_address = htmlspecialchars(addslashes(trim($_POST['Facility_Address']))); </code></pre>
 

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