SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
-
Oct 8, 2004, 14:07 #1
- Join Date
- Jul 2004
- Location
- Minnesota
- Posts
- 24
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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');
<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');
}
Anybody out there run into this before, or know how to get this going???
Thanks!!!
-
Oct 8, 2004, 20:46 #2
- 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);
PHP Code:$categories = array ('value1' => 'option1', 'value2' => 'option2');
-
Oct 9, 2004, 08:07 #3
- 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'];
}
}
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