views:

628

answers:

1

I have a problem with slashes! I have some jQuery for handling generic dialogs on a page. In some cases the fields are passing /-delimited paths...

var fieldValues = [];
// pull values from all the fields belonging to the dialog...
$.each($(this).find('input, textarea, select'), function(n,field) {
  // escape the path fields
  var value = escape($(field).val().replace(/\//g,'__slash__'));
  //alert ($(field).attr('id')+'='+value);
  if(id != '' && value != '') {
    fieldValues.push(id+'='+value);
  }
});

This code works, but I have a manual stripping out of __slash__ when I get to the php end of things. Is there some encoding function I'm missing that would let me drop the clumsy-looking replace?

+1  A: 

You can use Javascript's built-in encodeURIComponent() and then PHP's rawurldecode() should decode it in PHP once received.

Andrew Marshall
Well, did this work/help?
Andrew Marshall