SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Evangelist Tecknowjnkie's Avatar
    Join Date
    Nov 2004
    Location
    Mission Viejo
    Posts
    403
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Checkbox array is empty (when checkboxes are checked)

    I have a form containing checkboxes with name='catArr[]' and when checked and submitted print_r($_POST['catArr']) is empty. I can see them in LiveHeaders when the form is submitted. I have the identical form on another page and it works fine there and I can not find any errors in the form. It has to be some rediculous issue or typo yet I can not find it. I tried posting the code here but because it is a form it gets all hacked up. Any thoughts?

  2. #2
    SitePoint Evangelist
    Join Date
    Oct 2005
    Location
    Michigan, USA
    Posts
    434
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You should be able to post your code inside the php or code tags. Without seeing the code, though...

    Try print_r($_POST) and see if catArr is there at all.
    Is the page redirecting?
    - Robert

  3. #3
    SitePoint Evangelist Jhorra's Avatar
    Join Date
    Sep 2004
    Location
    Phoenix, Az
    Posts
    551
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When you post your code you need to put it inside {code} or {php} tags.

    Replace the { and } withe [ and ]

    Then it will display as raw code just as you see it and not try to render it.

  4. #4
    SitePoint Evangelist Tecknowjnkie's Avatar
    Join Date
    Nov 2004
    Location
    Mission Viejo
    Posts
    403
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As stated print_r($_POST['catArr']) returns an empty array as 'Array'

    Here is the code:

    PHP Code:
    <form id="newItem" method="post" action="products.php" enctype="multipart/form-data">
    <p><label for="product_name">Product Name</label><br/>
    <input type="text" name="product_name" /></p>
    <p><label for="product_description">Description</label><br/>
    <textarea id="product_description" name="product_description" rows="5" cols="30">
    </textarea></p>
    <p><label for="product_price">Product Price:</label><br/>
    <input type="text" name="product_price" /></p>
    <p><label for="product_height">Product Height</label><br/>
    <input type="text" name="product_height" /></p>
    <p><label for="product_width">Product Width</label><br/>
    <input type="text" name="product_width" /></p>
    <p><label for="product_weight">Product Weight</label><br/>
    <input type="text" name="product_weight" /></p>
    <table id="sCats">
    <caption>Choose Category(s)</caption>
    <?php 
    $columns 
    =4;
    $i=0;
    foreach(
    $prodSubCatArr as $subCat) {
        if((
    $i $columns) == 0) {
            echo 
    "<tr>\n";
            }
            echo 
    "<td><input type=\"checkbox\" name=\"catArr[]\" value=\"".$subCat['prodcatid']."\" /> ".$subCat['name'] ."</td>\n";
            if((
    $i $columns) == ($columns 1)) {
                echo 
    "</tr>\n";
                }
            
    $i++;
        } 
    ?>
    </table>
    <p><label for="product_image">Product Image:</label><br/>
    <input type="file" name="product_image" /></p>
    <input type="submit" id="submit" name="addItem" value="Add Item" />
    <input type="submit" value="Cancel" onclick="tb_remove()" />
    </form>

  5. #5
    SitePoint Addict
    Join Date
    Oct 2003
    Location
    United States
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Where is your opening form tag?

  6. #6
    SitePoint Evangelist Tecknowjnkie's Avatar
    Join Date
    Nov 2004
    Location
    Mission Viejo
    Posts
    403
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First line of displayed code

  7. #7
    SitePoint Addict
    Join Date
    Oct 2003
    Location
    United States
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's not there...

  8. #8
    SitePoint Wizard Hammer65's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln Nebraska
    Posts
    1,161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First thing to do, is to do a view source on the form, select the HTML source, copy and paste it into a new document, and then try submitting using just the HTML.

    If that gives you the same results than start simplifying the form. Make it a simple GET form and use print_r($_GET) comment out fields and so forth till you find the problem.
    Visit my blog
    PHP && Life
    for technology articles and musings.

  9. #9
    SitePoint Evangelist
    Join Date
    Oct 2005
    Location
    Michigan, USA
    Posts
    434
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I think the form is fine. Do print_r($_POST) at the very top of the file and see if anything at all is there. It may be reset somewhere later in the code.
    - Robert

  10. #10
    SitePoint Evangelist Tecknowjnkie's Avatar
    Join Date
    Nov 2004
    Location
    Mission Viejo
    Posts
    403
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The included file strip_quotes.php';

    which contains the below code was the culprit:
    PHP Code:
    /**
     * Checks for magic_quotes_gpc = On and strips them from incoming
     * requests if necessary
     */
    if (get_magic_quotes_gpc())
    {
      
    $_GET    array_map('stripslashes'$_GET);
      
    $_POST   array_map('stripslashes'$_POST);
      
    $_COOKIE array_map('stripslashes'$_COOKIE);

    Thank you for the help guys
    Last edited by Tecknowjnkie; Feb 20, 2008 at 12:16. Reason: Added Thank you

  11. #11
    SitePoint Wizard Hammer65's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln Nebraska
    Posts
    1,161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Which is why I suggested taking PHP out of the picture. Glad you got it working. Make a copy of superglobals and work with the copy. It is possible to re-write them but it avoids confusion if you don't.
    Visit my blog
    PHP && Life
    for technology articles and musings.


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
  •