Return to Snippet

Revision: 8499
at September 25, 2008 18:12 by mdrisser


Initial Code
<?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;
    }
}
?>

Initial URL
http://www.r1designs.net

Initial Description
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.

Initial Title
Assign POST/GET to internal array

Initial Tags
php, post, forms

Initial Language
PHP