SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member petemcw's Avatar
    Join Date
    Jul 2004
    Location
    Minnesota
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Problem HTML_QuickForms processing select array

    So I have a page created with HTML_QuickForms.
    I have it pumping out a <select> menu with info from my database. The select menu also has the "multiple" option set.

    So what I want to do is simply process that select menu. It instead of the expected array of selected options, the variable is returning as "string[5] Array". It is returning the actual word "Array".

    I can't figure this out. I have other forms on other sites where this works fine, but the form is just hard coded. For whatever reason, I think the HTML_QuickForm is screwing it all up.

    Here is part of the code...
    PHP Code:
    // Instantiate the QuickForm Class
        
    $form = new HTML_QuickForm('submitForm1''POST');
        
        
    // The headline field
        
    $form->addElement('text''headline''Headline: ''size="40"');
        
    $form->addRule('headline''Please enter a headline''required'false);
        
    $form->addRule('headline''Headlines cannot be more than 100 characters''maxlength'100);

        
    // The category field
        
    $select =& $form->createElement('select','category','Category: ');
        
    $select->loadArray($categories);
        
    $select->setMultiple(true);
        
    $form->addElement($select);

        
    // Add Submit Button
        
    $form->addElement('submit''submit''Go to Step 2'); 
    That creates the form properly like:
    <select name="category[]" multiple>....

    This is how I think I am suppose to process the form, it works fine for any text field, textarea, checkbox, etc.

    PHP Code:
    // If the form is submitted ...
        
    if ($form->validate())
        {
            
    // Apply the escape filter to all fields
            
    $form->applyFilter('__ALL__''escapeValue');
            
            
    $headline $form->getSubmitValue('headline');
            
    $category $form->getSubmitValue('category');
                    
            
    header('Location: release_step2.php');
        } 
    I have tried numerous other ways of getting the data, such as $_POST['category'], etc. but it always seems to come back as a string with the value "Array".

    Anybody out there run into this before, or know how to get this going???
    Thanks!!!

  2. #2
    SitePoint Zealot ssttoo's Avatar
    Join Date
    Jan 2004
    Location
    LA, California
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Everything looks perfect with the code. There's nothing wrong.
    Could you paste here the value of $categories that you pass here:
    PHP Code:
    $select->loadArray($categories); 
    It should be OK if it's something like:
    PHP Code:
    $categories = array ('value1' => 'option1''value2' => 'option2'); 

  3. #3
    SitePoint Member petemcw's Avatar
    Join Date
    Jul 2004
    Location
    Minnesota
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey, yeah this is pretty weird, huh.
    The code for the categories is:

    PHP Code:
    // Get Categories
        
    $sql 'SELECT * FROM _categories ORDER BY id ASC';
        
    $results $db->query($sql);
        if (!
    $results->isError())
        {
            while (
    $row $results->fetch())
            {
                
    $categories[$row['id']] = $row['category_name'];
            }
        } 
    This gives me a value/name pair basically and loads up the menu great!
    I just can't get the selected values after the form is posted.

    I am even having trouble with HTML_QuickForm's own date psuedo-element. I can get the elements to display properly, but again, I can't get the values after post...just a string value of "Array".


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
  •