Hi,
I've a litte question:
$wgRequest->getVal('_naw_title') result nothing, when post-name="_naw_title[]".
What's going wrong thx Mic
Michael Heyder wrote:
Hi,
I've a litte question:
$wgRequest->getVal('_naw_title') result nothing, when post-name="_naw_title[]".
What's going wrong
WebRequest::getVal() returns a string or null. This protects against type errors from malicious submissions passing unexpected arrays.
If you're dealing explicitly with an array parameter, use $wgRequest->getArray() to enforce an array-or-null return.
-- brion vibber (brion @ wikimedia.org)
Brion Vibber schrieb:
Michael Heyder wrote:
Hi,
I've a litte question:
$wgRequest->getVal('_naw_title') result nothing, when post-name="_naw_title[]".
What's going wrong
WebRequest::getVal() returns a string or null. This protects against type errors from malicious submissions passing unexpected arrays.
If you're dealing explicitly with an array parameter, use $wgRequest->getArray() to enforce an array-or-null return.
-- brion vibber (brion @ wikimedia.org)
Brian,
thanks a lot.
Does getArray('fieldname') work for you? I'm having problems getting the list of values of a group of checkboxes using . $wgRequest->getArray('fieldname'), it only returns the last element.
For instance, I have a search form with with a group of checkboxes e.g. <input type="checkbox" value="Category1" name="categories" /> <input type="checkbox" value="Category2" name="categories" />
When the form is submitted via GET, the resulting URL has: categories=Category1&categories=Category2
in my extension, I use
$category_list = array(); $category_list = $wgRequest->getArray('categories'); $categoryString = join(",", $category_list);
echo $categoryString; // Prints out 'Category2'
Any obvious error in my approach?
Thanks,
-Carlos
Michael Heyder wrote:
Brion Vibber schrieb:
Michael Heyder wrote:
Hi,
I've a litte question:
$wgRequest->getVal('_naw_title') result nothing, when post-name="_naw_title[]".
What's going wrong
WebRequest::getVal() returns a string or null. This protects against type errors from malicious submissions passing unexpected arrays.
If you're dealing explicitly with an array parameter, use $wgRequest->getArray() to enforce an array-or-null return.
-- brion vibber (brion @ wikimedia.org)
Brian,
thanks a lot.
MediaWiki-l mailing list MediaWiki-l@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/mediawiki-l
Your array command is ok. But you're not using the right name. You need to use name="categories[]" in the inputs.
So for the checkboxes:
<input type="checkbox" value="Category1" name="categories[]" /> <input type="checkbox" value="Category2" name="categories[]" />
And the extension code stays the same:
$category_list = array(); $category_list = $wgRequest->getArray('categories'); $categoryString = join(",", $category_list);
Though... personally... You're using to much pointless code. (Also, it's implode, not join.) (And you're mixing 2 types of naming styles, camelCase and underscore separated) Here's how I'd do it. $categoryList = implode( ",", $wgRequest->getArray( 'categories', array() ) ); Those extra lines are useless. You'll also end up with some bad errors. (The first line is useless because it's always overridden. The second line can return null [Which you tried to fix with the first line but failed because you need a default]. And the last line uses a improper function.)
~Daniel Friesen(Dantman) of: -The Gaiapedia (http://gaia.wikia.com) -Wikia ACG on Wikia.com (http://wikia.com/wiki/Wikia_ACG) -and Wiki-Tools.com (http://wiki-tools.com)
Carlos Ramirez wrote:
Does getArray('fieldname') work for you? I'm having problems getting the list of values of a group of checkboxes using . $wgRequest->getArray('fieldname'), it only returns the last element.
For instance, I have a search form with with a group of checkboxes e.g.
<input type="checkbox" value="Category1" name="categories" /> <input type="checkbox" value="Category2" name="categories" />
When the form is submitted via GET, the resulting URL has: categories=Category1&categories=Category2
in my extension, I use
$category_list = array(); $category_list = $wgRequest->getArray('categories'); $categoryString = join(",", $category_list);
echo $categoryString; // Prints out 'Category2'
Any obvious error in my approach?
Thanks,
-Carlos
Michael Heyder wrote:
Brion Vibber schrieb:
Michael Heyder wrote:
Hi,
I've a litte question:
$wgRequest->getVal('_naw_title') result nothing, when post-name="_naw_title[]".
What's going wrong
WebRequest::getVal() returns a string or null. This protects against type errors from malicious submissions passing unexpected arrays.
If you're dealing explicitly with an array parameter, use $wgRequest->getArray() to enforce an array-or-null return.
-- brion vibber (brion @ wikimedia.org)
Brian,
thanks a lot.
MediaWiki-l mailing list MediaWiki-l@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/mediawiki-l
MediaWiki-l mailing list MediaWiki-l@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/mediawiki-l
Daniel, Excellent...it works! Thanks so much for your help and the coding tips.
-Carlos
DanTMan wrote:
Your array command is ok. But you're not using the right name. You need to use name="categories[]" in the inputs.
So for the checkboxes:
<input type="checkbox" value="Category1" name="categories[]" /> <input type="checkbox" value="Category2" name="categories[]" />
And the extension code stays the same:
$category_list = array(); $category_list = $wgRequest->getArray('categories'); $categoryString = join(",", $category_list);
Though... personally... You're using to much pointless code. (Also, it's implode, not join.) (And you're mixing 2 types of naming styles, camelCase and underscore separated) Here's how I'd do it. $categoryList = implode( ",", $wgRequest->getArray( 'categories', array() ) ); Those extra lines are useless. You'll also end up with some bad errors. (The first line is useless because it's always overridden. The second line can return null [Which you tried to fix with the first line but failed because you need a default]. And the last line uses a improper function.)
~Daniel Friesen(Dantman) of: -The Gaiapedia (http://gaia.wikia.com) -Wikia ACG on Wikia.com (http://wikia.com/wiki/Wikia_ACG) -and Wiki-Tools.com (http://wiki-tools.com)
Carlos Ramirez wrote:
Does getArray('fieldname') work for you? I'm having problems getting the list of values of a group of checkboxes using . $wgRequest->getArray('fieldname'), it only returns the last element.
For instance, I have a search form with with a group of checkboxes e.g.
<input type="checkbox" value="Category1" name="categories" /> <input type="checkbox" value="Category2" name="categories" />
When the form is submitted via GET, the resulting URL has: categories=Category1&categories=Category2
in my extension, I use
$category_list = array(); $category_list = $wgRequest->getArray('categories'); $categoryString = join(",", $category_list);
echo $categoryString; // Prints out 'Category2'
Any obvious error in my approach?
Thanks,
-Carlos
Michael Heyder wrote:
Brion Vibber schrieb:
Michael Heyder wrote:
Hi,
I've a litte question:
$wgRequest->getVal('_naw_title') result nothing, when post-name="_naw_title[]".
What's going wrong
WebRequest::getVal() returns a string or null. This protects against type errors from malicious submissions passing unexpected arrays.
If you're dealing explicitly with an array parameter, use $wgRequest->getArray() to enforce an array-or-null return.
-- brion vibber (brion @ wikimedia.org)
Brian,
thanks a lot.
MediaWiki-l mailing list MediaWiki-l@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/mediawiki-l
MediaWiki-l mailing list MediaWiki-l@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/mediawiki-l
MediaWiki-l mailing list MediaWiki-l@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/mediawiki-l
mediawiki-l@lists.wikimedia.org