Duplicate in$_POST
Posted: 17 January 2008 11:31 PM   [ Ignore ]  
Lab Assistant
RankRank
Total Posts:  180
Joined  06-04-2007

Hey all,
I have something weird happening here. In a module I have developed, I have a Form posting a series of checkboxes to $_POST as an array.. ie:

$r .= $DSP->input_checkbox("groups[]", $row['id'] , $selected ).NBS.$row['cat_name'];

as you can see the checkboxes are posting as an array
The output $POST array contains the groups array pefectly like this:

groups[] => array([0]=>123, [1]=>456, [2]=>789)


thats perfect, but for some reason it is also appending , and auto-incrementing it seems, separate values at the end of the $_POST array like so:

[groups_0]=>123 [groups_1]=>456 [groups_2]=> 789

which is weird.

The function is fairly simple, so i wont post it here, ive looked at the 3 lines very closely and no, theres nothing that could be adding to $POST like that.

Im wondering if its a bug or maybe something that is supposed to happen when using $DSP->input_checkbox?

Profile
 
 
Posted: 18 January 2008 06:25 AM   [ Ignore ]   [ # 1 ]  
Grad Student
Avatar
Rank
Total Posts:  62
Joined  10-17-2007

how about

$selected, '')

without the space?

 Signature 

Best Regards,
Corvaire Wind
(aka, BurningTroll, MX Guru, WillmKing)

Profile
 
 
Posted: 18 January 2008 06:36 AM   [ Ignore ]   [ # 2 ]  
Lab Assistant
RankRank
Total Posts:  180
Joined  06-04-2007

yeah, i put that in there to see what would happen…  it still does it without that extra ‘’;..

edited the above code..

Profile
 
 
Posted: 18 January 2008 08:12 AM   [ Ignore ]   [ # 3 ]  
Grad Student
Avatar
Rank
Total Posts:  62
Joined  10-17-2007

try taking the period off the front of NBS and see what that does.

 Signature 

Best Regards,
Corvaire Wind
(aka, BurningTroll, MX Guru, WillmKing)

Profile
 
 
Posted: 31 January 2008 07:23 PM   [ Ignore ]   [ # 4 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1330
Joined  02-12-2003

Vinci,

I know you didn’t want to post the whole function but can you do that anyway?

Jamie

Profile
 
 
Posted: 19 August 2008 07:09 AM   [ Ignore ]   [ # 5 ]  
Lab Assistant
RankRank
Total Posts:  180
Joined  06-04-2007

A few months on an ANOTHER module, and I am getting the same issue.

Simple form data, to post into an array within $_POST.
I have say, a very simple form:

<input type="text" name="1[this]" value="xx"/>
<
input type="text" name="1[that]" value="yy"/>

$_POST on the processing page will look like:

[1] => array([this] => xx, [that] => yy), [1_this] => xx, [1_that] => yy


Those last two variables SHOULDNT be there,

Does anyone think this could be a server issue (im using MAMP), such as an apache module messing with $_POST? or heaven forbid missed EE setting.. or worst case, EE bug?

Profile
 
 
Posted: 19 August 2008 07:52 AM   [ Ignore ]   [ # 6 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  716
Joined  07-02-2007

EE always does that, don’t know why.

If you have:
<input name=“cat[]” value=“bla”>
<input name=“cat[]” value=“foo”>
<input name=“cat[]” value=“owyeah”>

Your $_POST array will be:

array(
cat => array('bla','foo','owyeah'),
cat_1 => 'bla',
cat_2 => 'foo',
cat_3 => 'owyeah'
)

If i am mistaken that this is an EE “feature” please correct me.

 Signature 

Truly ExpressionEngine


Fielder Module ( Mass Custom Fields )
Super Cache (Cache heavy tag output)
reCAPTCHA Extension
Rewrite Module


See all my EE Addons (8)

Profile
 
 
Posted: 19 August 2008 08:46 PM   [ Ignore ]   [ # 7 ]  
Lab Assistant
RankRank
Total Posts:  180
Joined  06-04-2007

Feature? its annoying as I will have to do quite a few preg_match’s on the $keys of the array to remove them!

is there an ‘off’ button anywhere?

Profile
 
 
Posted: 19 August 2008 09:30 PM   [ Ignore ]   [ # 8 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  716
Joined  07-02-2007
vinci - 19 August 2008 08:46 PM

Feature? its annoying as I will have to do quite a few preg_match’s on the $keys of the array to remove them!

is there an ‘off’ button anywhere?


No need for regex,

foreach ($_POST as $key => $value)
{
    
if (is_numeric(substr($key, 0, 1)) === TRUE)
    
{
        
unset $_POST[$key];
    
}

}


This code beats regex in speed.

 Signature 

Truly ExpressionEngine


Fielder Module ( Mass Custom Fields )
Super Cache (Cache heavy tag output)
reCAPTCHA Extension
Rewrite Module


See all my EE Addons (8)

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 64919 Total Logged-in Users: 24
Total Topics: 81873 Total Anonymous Users: 16
Total Replies: 440157 Total Guests: 198
Total Posts: 522030    
Members ( View Memberlist )