Ilian Andreev
Ilian Andreev

Reputation: 1091

Why doesn't PHP auto html decode my POST?

I'm using Zend Framework for a project. Why when I make POST request and get the params in my controller by $this->_request->getParams() it shows undecoded values? For example a string like Speakers & keyboards in my HTML form is retrieved as Speakers & keyboards from getParams() within PHP.

Doesn't PHP autodecode every posted value?

Upvotes: 0

Views: 990

Answers (3)

Quentin
Quentin

Reputation: 943240

Hi John, thanks for the hint! I think that's the problem really as I'm making an AJAX POST request and it takes data from the page HTML. So I better use something like urlDecode() before sending the request... What do you think?

The problem then, is that you are sending HTML and you want text.

When you grab the content from the page, get text instead of HTML. So don't use innerHTML or jQuery's .html(). Get a textNode and read its data property, or use jQuery's .text().

Upvotes: 2

John Green
John Green

Reputation: 13435

PHP autodecodes the escaped content, not content which is in HTML entities.

Upvotes: 1

Quentin
Quentin

Reputation: 943240

Because there is no reason to do so.

Data is encoded for transport, and then decoded again. HTML isn't an encoding used for transport.

The only reason to expect to receive HTML is if HTML was sent, and if HTML is sent then (presumably) HTML is desired. Converting to text wouldn't often be a desired thing to happen next.

Upvotes: 1

Related Questions