Posted By

mdrisser on 09/25/08


Tagged

get php post forms


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

mdrisser
brent-man


Assign POST/GET to internal array


 / Published in: PHP
 

URL: http://www.r1designs.net

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.

  1. <?php
  2. // Loop through the fields in the POST and assign them to our internal variable.
  3. // There are several special cases we need to handle differently, so we'll skip
  4. // them for now.
  5. foreach($_POST as $key=>$value) {
  6. switch($key) {
  7. case 'submit'; // Completely skip over the submit button
  8. case "field_1";
  9. case "/^a\ regex$/";
  10. case "field_20";
  11. default:
  12. $myArray[$key] = $value;
  13. }
  14. }
  15. ?>

Report this snippet  

You need to login to post a comment.