required_param and optional_param

required_param and optional_param

by Juliette Culver -
Number of replies: 5
Would it make sense for the required_param and optional_param functions to also be able to return an appropriate value from $_REQUEST as well as $_POST and $_GET? It might pre-empt various problems down the line with people using Ajax.   
Average of ratings: -
In reply to Juliette Culver

Re: required_param and optional_param

by sam marshall -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers
The only difference is that $_REQUEST includes $_COOKIE, isn't it?

I don't see what this would have to do with Ajax in other words smile There must be something I'm missing?

--sam
In reply to sam marshall

Re: required_param and optional_param

by Juliette Culver -
You're probably right and there's nothing subtle going on, but every single Ajax tutorial / bit of documentation uses $_REQUEST and I've been slavishly following them at least until I've got everything working smile And if I am, then probably other people will too.
In reply to Juliette Culver

Re: required_param and optional_param

by Juliette Culver -
Actually I did experiment with using $_POST instead this morning and it didn't work but I don't know enough about all that sort of stuff to know whether it should have done or if it didn't why not. 
In reply to Juliette Culver

Re: required_param and optional_param

by sam marshall -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers
I haven't bothered to look at Ajax stuff in detail yet (will be coding some soon). However, you can make XMLHttpRequest use any method, as a quick search for docs revealed:

open("method", "URL"[, asyncFlag[, "userName"[, "password"]]])

If you set method to POST then $_POST will work; if you set it to GET then $_GET will work. After a quick read through the docs, it seems to me that you can't set cookies using XMLHttpRequest (it always uses the browser standard ones) so there should be no situation [barring stupid ones where the same parameter is defined in different places] in which checking $_POST and $_GET together would not be equivalent to checking $_REQUEST from the point of view of input parameters. The PHP manual states that $_REQUEST is equal to $_POST + $_GET + $_COOKIE.

By the way if you want a second pair of eyes for fixing this stuff, I might be able to come over and take a look (since I need to know it soon anyway!).

--sam

In reply to sam marshall

Re: required_param and optional_param

by Juliette Culver -
I tried it with $_POST just now and it worked this time. Must have been doing something else wrong before... Maybe the coding standards will need to say not to use $_REQUEST so that people don't skip the cleaning up that they ought to do?