Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-29-2013, 03:41 AM   PM User | #1
doubledee
Regular Coder

 
doubledee's Avatar
 
Join Date: Mar 2011
Location: Arizona
Posts: 617
Thanks: 19
Thanked 0 Times in 0 Posts
doubledee has a little shameless behaviour in the past
What Values get submitted with this Form?

When the following Form gets submitted...

PHP Code:
<fieldset id='requestChoices'>
    <
input name='friendRequestDecision[38]' type='hidden' value='0' />

    <
input id='Requestor1_1' name='friendRequestDecision[38]' type='radio' value='0' checked='checked' />
    <
label for='Requestor1_1'>Decide Later</label>

    <
input id='Requestor1_2' name='friendRequestDecision[38]' type='radio' value='1'  />
    <
label for='Requestor1_2'>Accept</label>

    <
input id='Requestor1_3' name='friendRequestDecision[38]' type='radio' value='2'  />
    <
label for='Requestor1_3'>Decline</label>
</
fieldset

1.) What values get returned to my script?

2.) Is the first "hidden" field part of $_POST ?

3.) And is there a conflict between name='friendRequestDecision[38]' in my Hidden Input and in my Regular Inputs?


I put var_dump in my code and got this...
Code:
array
  'friendRequestDecision' => 
    array
      38 => string '1' (length=1)
      1 => string '1' (length=1)
  'submit' => string 'Update Requests' (length=15)
...but it still seems like the Hidden Input might be lingering out there?!


All of these questions are centered around SECURITY and making sure I check for the right values in the right places so that a hacker can't sneak in something bad?!

Sincerely,


Debbie

P.S. When I test the above code, it appears to be working okay as far of what is echoed on the screen and what gets updated in my database, but I figured I better check with the gurus here!!
doubledee is offline   Reply With Quote
Old 01-29-2013, 04:36 AM   PM User | #2
jalex718
New to the CF scene

 
Join Date: Jan 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
jalex718 is an unknown quantity at this point
When you set your input's name to anything containing [] in it, php picks it up as a mufti dimensional array, causing your output issue, use another delimiter such as varname_23 or you could do this...

PHP Code:
<?php
print_r
($_POST);
print_r(MultiArrayToSingle($_POST));
function 
MultiArrayToSingle ($array)
{
    
$my_post_vars = array();
    foreach (
$array as $key => $value)
    {
        if(
is_array($value))
        {
            foreach(
$value as $k => $v)
            {
                
$my_post_vars[$key."_".$k] = $v;    
            }
        }
        else
        {
            
$my_post_vars[$key] = $value;    
        }
    }
    return 
$my_post_vars;
}
?>
here was my result

From the $_POST variable
Array
(
[friendRequestDecision] => Array
(
[38] => 1
)

[button] => Submit
)

After $_POST was ran though my function
Array
(
[friendRequestDecision_38] => 1
[button] => Submit
)

Last edited by jalex718; 01-29-2013 at 04:40 AM..
jalex718 is offline   Reply With Quote
Old 01-29-2013, 02:51 PM   PM User | #3
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
You cannot share the same name with non-toggleable inputs. Radio and checkbox are fine as they require the same name in order to determine successful field groups. The hidden will be overwritten by the radio group following it. See your var dump results, you have selected accept for friendRequestDecision[38] and friendRequestDecision[1].
So to answer your question, yes both get submitted. But only the latter one is successful. I'm not sure why you want that hidden field though; even if no option is selected, it would be presumable that you cannot pass a non-existent id into a query to update. If you cannot do that, than it is implicitly ignored.
So in other words, the hidden input is useless.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:48 AM.


Advertisement
Log in to turn off these ads.