jquery Forms plugin

jquery Forms plugin


Hi All,
Inactivity in the forms mailing list unless I'm missing something.. so
anyway.
Interesting behaviour and comment on the Forms plugin ajaxSubmit.
I've been trying to get ajaxForm to work with cbparser - a php based
bbcode to html conversion utility. It's great and seems to do the
trick. Only problem was that newlines weren't working with jQuery/
AJAX.
Solution - ajaxSubmit posts newlines as %0A, whilst cbparser expects \r
\n. Standard posting (without ajax) also sends \r\n.. weird.. anyway.
I've found a quick JS function
function nl2br(text){
    text = escape(text);
    if(text.indexOf('%0D%0A') > -1)
    {
        re_nlchar = /%0D%0A/g ;
    }
    else if(text.indexOf('%0A') > -1)
    {
        re_nlchar = /%0A/g ;
    }
    else if(text.indexOf('%0D') > -1)
    {
        re_nlchar = /%0D/g ;
    }
    return unescape( text.replace(re_nlchar,'\r\n') );
}
that replaces newline characters with \r\n. So for jQuery forms you
simply do something similar to
beforeSubmit: doNewlines
function doNewlines(formData, jqForm, options) {
    for(var i=0; i < formData.length; i++)
    {
        if(formData[i].name=="mytextbox") // name of the textbox you want to
post.
        {
            formData[i].value = nl2br(formData[i].value);
        }
    }
return true;
}
This strips out the %0As and sends the request with \r\n instead. All
good :)
Comments appreciated.
thanks
benw