/ Published in: Perl
This is inspired by this http://www.cgi101.com/book/ch5/text.html so I'm using a similar example. In PHP you can combine a set of checkboxes into an array using square brackets like this:
Red
Green
Blue
Gold
PHP does not do this automatically but it's pretty simple to do if you filter by regular expressions.
Red
Green
Blue
Gold
PHP does not do this automatically but it's pretty simple to do if you filter by regular expressions.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
use CGI; $query = CGI::new(); my %fields_temp = $query->Vars; my %fields = (); if ( $key =~ /(.+)\[\]$/ ) { ## Handle PHP style array inputs $fields{$1} = $fields{$1} . ",". $fields_temp{$key}; } else{ $fields{$1} = $fields_temp{$key}; } } else { $fields{$key} = $fields_temp{$key}; } } unless ($key =~ /(.+)\[\]$/ ){ } }