Somanand Mn
Somanand Mn

Reputation: 1

I need both spaces and plus sign to be preserved in jquery

I am posting textarea value which is picked up by jquery and sent to php backend. Here's the problem I'm facing: if I use urldecode() in php, the + sign is not shown and if I use rawurldecode() the multiple spaces between the words and the new lines are not preserved

//jquery

    $('#Btn').on('click', function f()
    {
var v=escape($("#postT").val());
    });

//HTML

        <textarea id="postT" name="postT"></textarea>
         <input type="button" name="subp" id="Btn" value="Post" />

//php

//if i use urldecode()

         if(isset($_REQUEST['v']))
          {
           $T_post=urldecode($_REQUEST['v']);
          }
          echo $T_post;

//if I enter textarea value as 'hi+hello' result will be 'hi hello'. The + sign is not at all shown

//if i use rawurldecode()

           if(isset($_REQUEST['v']))
          {
           $T_post=rawurldecode($_REQUEST['v']);
          }
          echo $T_post;

//if I enter textarea value as 'hi hello' result will be 'hi hello'. only one space is shown instead of so many spaces between the words

But I want both things to happen like preserving as many spaces I have entered into textarea and showing the + sign as well.

thank you

Upvotes: 0

Views: 280

Answers (1)

user2803444
user2803444

Reputation: 21

var v = encodeURIComponent($("#postT").val());

Upvotes: 1

Related Questions