Howto? array value in a select

190 views
Skip to first unread message

TheSin

unread,
May 8, 2013, 4:27:17 PM5/8/13
to php-form-bu...@googlegroups.com
I have a form with a bunch of selects and for processing I want to distinguish certain blocks, the easiest way is to make the names of the select as html arrays

example

color[primary]
color[secondary]

size[a]
size[b]

this is all legal and works form/html wise and I get the post I require.

The problem is with validation.  My JS validation passes but I'm getting an error in Validation/Required.php, Saying those selects are missing values, when I check in the Session the values aren't being set in values.  So somethings tells me that something that sets the values doesn't like arrays in select, is this true, does anyone have an tips to save me time on where to look?  I'm going to dive in but thought I'd post and ask first if nothing else I can post the solution to help out others.

Andrew Porterfield

unread,
May 8, 2013, 4:39:46 PM5/8/13
to php-form-bu...@googlegroups.com
You'll want to check out the Form class' isValid method - https://code.google.com/p/php-form-builder-class/source/browse/branches/3.x-php5/PFBC/Form.php#142.
> --
> You received this message because you are subscribed to the Google Groups "php-form-builder-class" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to php-form-builder-...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

TheSin

unread,
May 8, 2013, 5:08:40 PM5/8/13
to php-form-bu...@googlegroups.com
Based on that section I expanded it at line 170 from

                           $data[$name] = $_FILES[$name]["name"];

                      if(isset($data[$name])) {
                          $value = $data[$name];

to
                                                $data[$name] = $_FILES[$name]["name"];

                                        unset($value);
                                        if(strpos($name, "[") && strpos($name, "]")) {
                                                // HTML array
                                                $array = explode("[", $name);
                                                foreach ($array as $key => $val)
                                                        $array[$key] = rtrim($val, "]");

                                                $parts = count($array);

                                                $value = $data;
                                                for ($i = 0; $i < $parts; $i++)
                                                        $value = $value[$array[$i]];        
                                        } else if(isset($data[$name]))
                                                $value = $data[$name];

                                        if(isset($value)) {

this is just a quick dirty fix, and I'm still testing but so far it's working it seems.
Reply all
Reply to author
Forward
0 new messages