/ Published in: PHP
                    
                                        
I'm working on a web app that requires me to track nearly 300 form fields. To make this easier, and to allow me to handle special cases, I needed to assign them to an internal array. The switch/case statement makes this a breeze.
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
<?php
// Loop through the fields in the POST and assign them to our internal variable.
// There are several special cases we need to handle differently, so we'll skip
// them for now.
foreach($_POST as $key=>$value) {
switch($key) {
case 'submit'; // Completely skip over the submit button
case "field_1";
case "/^a\ regex$/";
case "field_20";
default:
$myArray[$key] = $value;
}
}
?>
Comments
 Subscribe to comments
                    Subscribe to comments
                
                