Page 1 of 1

Prototype Ajax Urlencode

Posted: Wed Mar 28, 2007 9:43 pm
by chris12295
I am having trouble using prototype to send an ajax request. I have a textarea that needs to have newlines in it but for some reason when i decode the value in php, it will not store in the database. Here is mycode:

Code: Select all

function leaveNote() {
	var note = escape(el('leavenote').value);
	var to = el('tid').value;
	var from = el('fid').value;
	var node = el('mynotes');
    new Ajax.Updater('mynotes', 'inc/ajax.php',
    {
		method:'post',
		parameters: {f: 'leaveNote', message: note, tid: to, fid: from},
		onComplete: function(transport){
		  node.removeChild(node.childNodes[5]);
		},
		onFailure: function(){ alert('Unable to leave note.') },
		insertion: Insertion.Top
    });
	
	return false;
}
here is the function that will be called from the ajax request:

Code: Select all

function leaveNote() {
 $timestamp = time();
 $_POST['message'] = urldecode($_POST['message']);
 $q = "INSERT INTO notes (tid, fid, message, created) VALUES('$_POST[tid]', '$_POST[fid]', '$_POST[message]', '$timestamp')";
 $GLOBALS['db']->query($q);
 $u = new user();
 $noteInfo = $u->getInfo('name, pic_xs', $_POST['fid']);
 $noteInfo = $noteInfo[0];
 if(empty($noteInfo['pic_xs'])) $noteInfo['pic_xs'] = 'img/nopicxs.gif';
 echo '<div><a href="profile.php?id='.$_POST['fid'].'" class="cover"><img src="'.$noteInfo['pic_xs'].'" /><h4>'.$noteInfo['name'].'</h4>'.date('m/j/y H:i', $timestamp).'<br />'.$_POST['message'].'</a><br clear="all"></div>';
}

if(function_exists($_POST['f'])) $_POST['f']();

Posted: Thu Mar 29, 2007 7:52 am
by Benjamin
Have you checked to see if the data being entered into the DB has line feeds? Why not check it every step of the way so you can find where the LF's are being removed?

Posted: Thu Mar 29, 2007 10:11 am
by chris12295
Well its not that the data is stored without the line feeds, its that it will not store any data at all in the database.