Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 759145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:33:42+00:00 2026-05-14T15:33:42+00:00

I have a real simple form with a textbox and a button, and my

  • 0

I have a real simple form with a textbox and a button, and my goal is to have an asynchronous request (jQuery: $.ajax) send the text to the server (PHP/mysql a la Joomla) so that it can be added to a database table.

Here’s the javascript that is sending the data from the client:

var value= $('#myvalue').val();

$.ajax( {
    type:       "POST",
    url:        "/administrator/index.php",
    data:       {   option: "com_mycomponent",
                    task:   "enterValue",
                    thevalue: value,
                    format: "raw"},
    dataType:   "text",
    success:    reportSavedValue
} );

The problem arises when the user enters text with a space in it. The $_POST variable that I receive has all the spaces stripped out, so that if the user enters “This string has spaces“, the server gets the value “Thisstringhasspaces“.

I have been googling around, and have found lots of references that I need to use encodeURIComponent. So I have tried it, but now the value that I get from $_POST is “This20string20has20spaces“.

So it appears to be encoding it the way I would expect, only to have the percent signs stripped instead of the spaces, and leaving the hex numbers.

I’m really confused. It seems that this sort of question is asked and answered everywhere on the web, and everywhere encodeURIComponent is hailed as the silver bullet. But apparently I’m fighting a different breed of lycanthrope. Does anyone have any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T15:33:42+00:00Added an answer on May 14, 2026 at 3:33 pm

    It turns out that there was extra filtering I didn’t realize I was performing. Because this was all running through Joomla, I was using JRequest::getCmd('thevalue') instead of $_POST['theValue]. This function, it turns out, filters out all those troublesome characters, like ‘%’.

    So the final solution is to use encodeURIComponent on the client, as is unanimously suggested on the web:

    var value = encodeURIComponent($('#myvalue').val());
    

    And on the server, to trade getCmd() for getVar() which allows more control over the filtering, in combination with urldecode():

    $value = urldecode(JRequest::getvar('thevalue', JREQUEST_ALLOWHTML));
    

    Again, big thanks to Karim79 and Cesar. I dub thee Harker and Helsing — my heroes for the day! 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to jQuery so this may be a real simple answer. I have
I have learned Perl and PHP.So I want to do simple real time project
I have a real basic form (code below) with a bunch of back-panel PhP.
I have large text in System.Windows.Forms.TextBox control in my form (winforms), vs 2008. I
I have a simple form that inserts data in a table on my server.
I have a simple contact form on a website that has 2 text fields,
I have a simple html form and some php that input the POST variables
I am trying to create a simple registration form. I have the following: include('User.datatype.php');
I have a simple form with some PHP code to post to a database
This is a real newbie question. I have simple app that selects a picture

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.