Discussion:
Strange string behavior...
Don Wieland
2014-08-13 17:41:10 UTC
Permalink
Hi gang,

I have an issue with updating a text field called "appt_notes" with a string that uses the & and + characters. On one of the forms (which uses AJAX), it does not save the entire text. For example, if I try to save this text:

Right hip + left knee replacement, in a lot of pain, "tried everything" - wants "deep work" - last massage didn't work, rieki and feldon crais didn't work, epidural two weeks ago backfired, still in pain. -DOH

It only saves "Right hip"

The one form from my Appt UI that uses an AJAX call is the one that does not work. Here is the AJAX code:

function saveAppt(no_reload){
try {
var id = $('input[name=id]').val();
var linkid = $('#linkid').val();
var status = $('select[name=status]');
var clientid = $('input[name=clientid]');
var modality = $('select[name=modality]');
var date_start = $('input[name=date_start]');
var time_from = $('select[name=time_from]');
var time_to = $('select[name=time_to]');

var time_field = $('#time_field');
var room = $('select[name=room]');
var user = $('select[name=user]');
var notes = $('textarea[name=notes]');
var appt_notes = $('textarea[name=appt_notes]');
var no_adj = $('input[name=no_adj]:checked').val();
var no_appt_calls = $('input[name=no_appt_calls]:checked').val();
var vml = $('input[name=vml]:checked').val();
var conf_appts_via = $('select[name=conf_appts_via]');
var ins_form = $('input[name=ins_form]:checked').val();

if(typeof id == 'undefined') id = '';
if(typeof linkid == 'undefined') linkid = '';
if(typeof no_appt_calls == 'undefined') no_appt_calls = '';
if(typeof vml == 'undefined') vml = '';

if(modality.val()=='' || modality.val()==null){
$('#mod_cell').addClass('highlight');
return false;
}else{
$('#mod_cell').removeClass('highlight');
}

/*var status_old = $('#db_status_appt').val();
if(status_old == 6 || status_old == 7 || status_old == 11 && ($('#db_status_appt'))) {
$('#status').addClass('highlight');
$('#status').val(status_old);
alert("This STATUS is not allowed because there is a related invoice/payment already created. You will need to delete payment and invoice first.");
return false;
}*/

if((notes.val() == '') && (status.val() == 6 || status.val() == 7 || status.val() == 11 || status.val() == 10)) {
$('#notes').addClass('highlight');
alert("This STATUS requires that you enter a REASON in the Note field");
return false;
}

time_diff = (time_to.val().substr(0,2) - time_from.val().substr(0,2))*60+(time_to.val().substr(2,2)-time_from.val().substr(2,2));

if(time_diff <= 0){
time_field.addClass('highlight');
alert('Min interval is 15 min');
return false;
}else{
time_field.removeClass('highlight');
}


var data = 'act=appt&save=1&id='+id+'&linkid='+linkid+'&clientid='+clientid.val()+'&status='+status.val()+'&modality='+modality.val()+'&date='+date_start.val()+'&time_from=' + time_from.val()+'&time_to=' + time_to.val()+'&room=' + room.val()+'&user=' + user.val()+ '&notes=' + notes.val() + '&appt_notes=' + appt_notes.val() + '&no_appt_calls=' + no_appt_calls + '&vml=' + vml + '&no_adj=' + no_adj + '&conf_appts_via=' + conf_appts_via.val()+ '&ins_form='+ins_form;

$('.inputField').attr('disabled','true');
$('.button').attr('disabled','true');

$('.loading').html(loading_img);

$.ajax({
url: "/utils.php",

type: "POST",

data: data,

cache: false,

success: function (html) {
data_ar = html.split('|');
data_ar[0]=data_ar[0].replace("\n","");
if (data_ar[0]=='id') {
$('.inputField').attr('disabled',false);
$('.button').attr('disabled',false);
$('.loading').html('');

if(no_reload!='1') {
//$('#apptform').fadeOut('slow');
//$('#appt_done').fadeIn('slow');

loadAppt(date_start.val(),'',room.val(), clientid.val(), data_ar[1], $('#av_id').val());
}
//loadCalendar();
//hideDialog();
//alert("\""+html+"1\"");
return true;
} else {
$('.inputField').attr('disabled',false);
$('.button').attr('disabled',false);
$('.loading').html(' ');
//alert("\""+html+"2\"");
jAlert(html.length>0?html:'Sorry, unexpected error. Please try again later.') ;
return false;
};
}
});

return true;

} catch(err){
txt="There was an error on this page.\n\n";
txt+="Error description: " + err.description + "\n\n";
txt+="Click OK to continue.\n\n";
alert(txt);

}
}

The one form from my Client UI that DOES NOT use an AJAX call works. It, also, uses a function to prepare the string to insert into mySQL:

function prepare_input($string) {
if (is_string($string)) {
return trim(stripslashes($string));
} elseif (is_array($string)) {
reset($string);
while (list($key, $value) = each($string)) {
$string[$key] = $this->prepare_input($value);
}
return $string;
} else {
return $string;
}
}

then in the PHP, it is coded like this:

$no_appt_calls = $_REQUEST['no_appt_calls'];


I am really stumped on why it works kine at the Client UI level, but not at the Appt UI level.

Any clues or assistance would be apreciated. Thanks!


Don Wieland
D W D a t a C o n c e p t s
~~~~~~~~~~~~~~~~~~~~~~~~~
***@dwdataconcepts.com
http://www.dwdataconcepts.com
Direct Line - (949) 336-4828
SKYPE - skypename = dwdata

Integrated data solutions to fit your business needs.

Need assistance in dialing in your FileMaker solution? Check out our Developer Support Plan at:
http://www.dwdataconcepts.com/DevSup.php

Appointment 1.0v9 - Powerful Appointment Scheduling for FileMaker Pro 9 or higher
http://www.appointment10.com

For a quick overview -
http://www.appointment10.com/Appt10_Promo/Overview.html
David OBrien
2014-08-13 18:18:38 UTC
Permalink
Post by Don Wieland
Hi gang,
I have an issue with updating a text field called "appt_notes" with a
string that uses the & and + characters. On one of the forms (which uses
AJAX), it does not save the entire text. For example, if I try to save this
Right hip + left knee replacement, in a lot of pain, "tried everything" -
wants "deep work" - last massage didn't work, rieki and feldon crais didn't
work, epidural two weeks ago backfired, still in pain. -DOH
It only saves "Right hip"
The one form from my Appt UI that uses an AJAX call is the one that does
function saveAppt(no_reload){
try {
var id = $('input[name=id]').val();
var linkid = $('#linkid').val();
var status = $('select[name=status]');
var clientid = $('input[name=clientid]');
var modality = $('select[name=modality]');
var date_start = $('input[name=date_start]');
var time_from = $('select[name=time_from]');
var time_to = $('select[name=time_to]');
var time_field = $('#time_field');
var room = $('select[name=room]');
var user = $('select[name=user]');
var notes = $('textarea[name=notes]');
var appt_notes = $('textarea[name=appt_notes]');
var no_adj = $('input[name=no_adj]:checked').val();
var no_appt_calls =
$('input[name=no_appt_calls]:checked').val();
var vml = $('input[name=vml]:checked').val();
var conf_appts_via = $('select[name=conf_appts_via]');
var ins_form = $('input[name=ins_form]:checked').val();
if(typeof id == 'undefined') id = '';
if(typeof linkid == 'undefined') linkid = '';
if(typeof no_appt_calls == 'undefined') no_appt_calls = '';
if(typeof vml == 'undefined') vml = '';
if(modality.val()=='' || modality.val()==null){
$('#mod_cell').addClass('highlight');
return false;
}else{
$('#mod_cell').removeClass('highlight');
}
/*var status_old = $('#db_status_appt').val();
if(status_old == 6 || status_old == 7 || status_old == 11
&& ($('#db_status_appt'))) {
$('#status').addClass('highlight');
$('#status').val(status_old);
alert("This STATUS is not allowed because there is
a related invoice/payment already created. You will need to delete payment
and invoice first.");
return false;
}*/
if((notes.val() == '') && (status.val() == 6 ||
status.val() == 7 || status.val() == 11 || status.val() == 10)) {
$('#notes').addClass('highlight');
alert("This STATUS requires that you enter a
REASON in the Note field");
return false;
}
time_diff = (time_to.val().substr(0,2) -
time_from.val().substr(0,2))*60+(time_to.val().substr(2,2)-time_from.val().substr(2,2));
if(time_diff <= 0){
time_field.addClass('highlight');
alert('Min interval is 15 min');
return false;
}else{
time_field.removeClass('highlight');
}
var data =
'act=appt&save=1&id='+id+'&linkid='+linkid+'&clientid='+clientid.val()+'&status='+status.val()+'&modality='+modality.val()+'&date='+date_start.val()+'&time_from='
+ time_from.val()+'&time_to=' + time_to.val()+'&room=' +
room.val()+'&user=' + user.val()+ '&notes=' + notes.val() + '&appt_notes='
+ appt_notes.val() + '&no_appt_calls=' + no_appt_calls + '&vml=' + vml +
'&no_adj=' + no_adj + '&conf_appts_via=' + conf_appts_via.val()+
'&ins_form='+ins_form;
$('.inputField').attr('disabled','true');
$('.button').attr('disabled','true');
$('.loading').html(loading_img);
$.ajax({
url: "/utils.php",
type: "POST",
data: data,
cache: false,
success: function (html) {
data_ar = html.split('|');
data_ar[0]=data_ar[0].replace("\n","");
if (data_ar[0]=='id') {
$('.inputField').attr('disabled',false);
$('.button').attr('disabled',false);
$('.loading').html('');
if(no_reload!='1') {
//$('#apptform').fadeOut('slow');
//$('#appt_done').fadeIn('slow');
loadAppt(date_start.val(),'',room.val(), clientid.val(), data_ar[1], $('#av_id').val());
}
//loadCalendar();
//hideDialog();
//alert("\""+html+"1\"");
return true;
} else {
$('.inputField').attr('disabled',false);
$('.button').attr('disabled',false);
$('.loading').html(' ');
//alert("\""+html+"2\"");
jAlert(html.length>0?html:'Sorry,
unexpected error. Please try again later.') ;
return false;
};
}
});
return true;
} catch(err){
txt="There was an error on this page.\n\n";
txt+="Error description: " + err.description + "\n\n";
txt+="Click OK to continue.\n\n";
alert(txt);
}
}
The one form from my Client UI that DOES NOT use an AJAX call works. It,
function prepare_input($string) {
if (is_string($string)) {
return trim(stripslashes($string));
} elseif (is_array($string)) {
reset($string);
while (list($key, $value) = each($string)) {
$string[$key] = $this->prepare_input($value);
}
return $string;
} else {
return $string;
}
}
$no_appt_calls = $_REQUEST['no_appt_calls'];
I am really stumped on why it works kine at the Client UI level, but not
at the Appt UI level.
Any clues or assistance would be apreciated. Thanks!
Don Wieland
D W D a t a C o n c e p t s
~~~~~~~~~~~~~~~~~~~~~~~~~
http://www.dwdataconcepts.com
Direct Line - (949) 336-4828
SKYPE - skypename = dwdata
Integrated data solutions to fit your business needs.
Need assistance in dialing in your FileMaker solution? Check out our
http://www.dwdataconcepts.com/DevSup.php
Appointment 1.0v9 - Powerful Appointment Scheduling for FileMaker Pro 9 or higher
http://www.appointment10.com
For a quick overview -
http://www.appointment10.com/Appt10_Promo/Overview.html
on the javascript side you'd use escape( variable ) to add slashes where
needed on all those variables

and when generating urls for get or post in php use urlencode which
converts the nasties like + into %20 and urldecode to get them back
Christoph Becker
2014-08-13 18:48:07 UTC
Permalink
Post by David OBrien
Post by Don Wieland
I have an issue with updating a text field called "appt_notes" with a
string that uses the & and + characters. On one of the forms (which uses
AJAX), it does not save the entire text.
<snip>
Post by David OBrien
Post by Don Wieland
$.ajax({
url: "/utils.php",
type: "POST",
data: data,
on the javascript side you'd use escape( variable ) to add slashes where
needed on all those variables
escape() is deprecated[1]; it's better to use encodeURI() resp.
encodeURIComponent() instead. However, in this case the Ajax request is
done with jQuery.ajax() so it is sufficient to set the data property to
an appropriate object[2]. Most likely it is even possible to simplify
the code considerably by using .serialize()[3].

[1]
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape>
[2] <http://api.jquery.com/jQuery.ajax/#jQuery-ajax-settings>
[3] <http://api.jquery.com/serialize/>
--
Christoph M. Becker
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Christoph Becker
2014-08-13 21:08:05 UTC
Permalink
Post by Christoph Becker
escape() is deprecated[1]; it's better to use encodeURI() resp.
encodeURIComponent() instead. However, in this case the Ajax request is
done with jQuery.ajax() so it is sufficient to set the data property to
an appropriate object[2]. Most likely it is even possible to simplify
the code considerably by using .serialize()[3].
[1]
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape>
[2] <http://api.jquery.com/jQuery.ajax/#jQuery-ajax-settings>
[3] <http://api.jquery.com/serialize/>
I am still stumped and I am not clear on how to effectively add the serialize() parameter to my javascript and even if I figure it out, I am not certain if that is my issue.
Right hip + left knee replacement, in a lot of pain, "tried everything" - wants "deep work" - last massage didn't work, rieki and feldon crais didn't work, epidural two weeks ago backfired, still in pain. -DOH
Right hip left knee replacement, in a lot of pain, \"tried everything\" - wants \"deep work\" - last massage didn\'t work, rieki and feldon crais didn\'t work, epidural two weeks ago backfired, still in pain. -DOH
---------------------
when I then change the + character to a &, this is what happens,
Right hip & left knee replacement, in a lot of pain, "tried everything" - wants "deep work" - last massage didn't work, rieki and feldon crais didn't work, epidural two weeks ago backfired, still in pain. -DOH
Right hip
-----
This one has me stumped.
$.ajax({
url: "/utils.php",
type: "POST",
data: data,
cache: false,
success: function (html) {
data_ar = html.split('|');
data_ar[0]=data_ar[0].replace("\n","");
if (data_ar[0]=='id') {
$('.inputField').attr('disabled',false);
$('.button').attr('disabled',false);
$('.loading').html('');
if(no_reload!='1') {
//$('#apptform').fadeOut('slow');
//$('#appt_done').fadeIn('slow');
loadAppt(date_start.val(),'',room.val(), clientid.val(), data_ar[1], $('#av_id').val());
}
//loadCalendar();
//hideDialog();
//alert("\""+html+"1\"");
return true;
} else {
$('.inputField').attr('disabled',false);
$('.button').attr('disabled',false);
$('.loading').html(' ');
//alert("\""+html+"2\"");
jAlert(html.length>0?html:'Sorry, unexpected error. Please try again later.') ;
return false;
};
}
});
I really see nothing in that code that looks suspicious. Although, I am not an expert in this area. How would you suggest I insert the serialize() function into this ajax call?
The jQuery documentation has a nice example:
<http://api.jquery.com/serialize/#example-0>. I suggest you have a
closer look at it. The return value of .serialize() can be used as
value of the "data" property of the jQuery.ajax() configuration object.

And please "reply to all" next time; a private conversation is of little
value for the other readers of the mailing list.
--
Christoph M. Becker
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Loading...