SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Wizard
    Join Date
    May 2003
    Location
    Berlin, Germany
    Posts
    1,829
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Array'd checkboxes do not parse as arrays :s

    HTML:
    Code:
    ....
    <input type="checkbox" name="groups[]" value="1"  />&nbsp;&nbsp;Administrators<br /><br />
    
    <h5>Remove  DarkAngelBGE from the following projects</h5>
    <input type="checkbox" name="projects[]" value="1"  />&nbsp;&nbsp;0.A.D.<br /><br />
    
    <h5>Remove  DarkAngelBGE from the following departments</h5>
    <input type="checkbox" name="departments[]" value="8"  />&nbsp;&nbsp;0.A.D.&nbsp;Web + Community Development<br /><br />
    PHP:

    PHP Code:
                    //-------------------------------------------
                    // Projects interpretation
                    //-------------------------------------------
                    
                    
    if( isset( $SITE->input['projects'] ) )
                    {
                        foreach( 
    $SITE->input['projects'] as $projectId )
                        {
                            
    $DB->query"DELETE FROM intr_user2project WHERE user_id = '{$SITE->input['userId']}' AND proj_id = '{$projectId}'" );
                        }
                    
                        
    $this->content .= "<p>{$name} successfully deleted from the project(s).</p>";
                    }
                    else
                    {                    
                        
    $this->content .= "<p>{$name} not deleted from any projects.</p>";
                    }
                
        
        
                    
    //-------------------------------------------
                    // Departments Interpretation
                    //-------------------------------------------
                    
    ... 
    As you see I grab the checkboxes with $SITE->input[someThing] (which works as $_POST, just secures the data). Now when I iterate over $SITE->input['projects'] for example (within the isset() statement ! ), I get wrong parameter for foreach. Echoeing it gives a string "Array".

    Anyone ?

  2. #2
    &lt;!-- Insert thoughts here --&gt; pitcher17's Avatar
    Join Date
    Apr 2004
    Location
    The great white north
    Posts
    293
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <input type="checkbox" name="groups[]" value="1" />
    ok, I'm assuming that you've got a series of checkboxes all called groups[].

    So, on the server side you could access the values of all the selected ones as
    PHP Code:
    echo $_POST['groups'][0]; 
    and so on...

    if this
    foreach( $SITE->input['projects'] as $projectId )
    works in the same way then $projectId would contain the array of items in $_POST['projects'] and you would have to loop through each of those.

    Or at least I think that makes sense
    The more time I save by not planning and documenting,
    the more time I have left to debug.


  3. #3
    SitePoint Wizard
    Join Date
    May 2003
    Location
    Berlin, Germany
    Posts
    1,829
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm..you have to know that $SITE->input['projects'] is the equivalent to $_POST['projects']. So just looping through it and not through each of its elements should work.

    Do you agree ?

  4. #4
    SitePoint Wizard
    Join Date
    May 2003
    Location
    Berlin, Germany
    Posts
    1,829
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The greatest thing of all is that it works on my local setup but not on my live server.

  5. #5
    &lt;!-- Insert thoughts here --&gt; pitcher17's Avatar
    Join Date
    Apr 2004
    Location
    The great white north
    Posts
    293
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you post the code for $SITE -> input['projects']?
    The more time I save by not planning and documenting,
    the more time I have left to debug.


  6. #6
    SitePoint Wizard
    Join Date
    May 2003
    Location
    Berlin, Germany
    Posts
    1,829
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You the code that makes $_POST['projects'] into $SITE->input['projects'] ?

    Sure, here it is:

    PHP Code:
        //-----------------------------------------------------------------------------
        // parseIncoming
        //
        // Inserts $_GET and $_POST into some more usable array and returns it
        //-----------------------------------------------------------------------------
        
        
    function parseIncoming()
        {
            global 
    $PATHVARS$_GET$_POST$HTTP_CLIENT_IP$_REQUEST$REMOTE_ADDR$HTTP_PROXY_USER$HTTP_X_FORWARDED_FOR;
                    
            
    $return = array();

            if( 
    get_magic_quotes_gpc() ) 
            {
                 
    $_GET    array_map'stripslashes'$_GET );
                 
    $_POST   array_map'stripslashes'$_POST );
                 
    $_COOKIE array_map'stripslashes'$_COOKIE );
            }
            
            if( 
    is_array($_GET) )
            {
                while( list(
    $k$v) = each($_GET) )
                {
                    if( 
    is_array$_GET[$k] ) )
                    {
                        while( list( 
    $k2$v2 ) = each$_GET[$k] ) )
                        {
                            
    $return[$k][ $this->cleanKey$k2 ) ] = $this->cleanValue$v2 );
                        }
                    }
                    else
                    {
                        
    $return[$k] = $this->cleanValue$v );
                    }
                }
            }
            
            
            
    $i 0;
            while (
    $var $PATHVARS->fetch()) 
            {
                
    $return[$i] = $this->cleanValue$var );
                
    $i += 1;
            }


            
    // Overwrite GET data with post data

            
    if( is_array$_POST ) )
            {
                while( list( 
    $k$v ) = each$_POST ) )
                {            
                    if ( 
    is_array$_POST[$k] ) )
                    {
                        while( list( 
    $k2$v2 ) = each($_POST[$k] ) )
                        {
                            
    $return[$k][ $this->cleanKey$k2 ) ] = $this->cleanValue$v2 );
                        }
                    }
                    else
                    {
                        
    $return[$k] = $this->cleanValue$v );
                    }
                }
            }
            
            return 
    $return;
        } 
    There is also the code for my PATHVARS (mod_rewrite) and $_GET. Ignore it.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •