note 51727 modified in language.variables.external by danbrown

From: Date: Wed, 09 Mar 2011 14:39:08 +0000
Subject: note 51727 modified in language.variables.external by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-177703@lists.php.net to get a copy of this message
To handle forms with or without [] you can do something like this: <?php function repairPost($data) { // combine rawpost and $_POST ($data) to rebuild broken arrays in $_POST $rawpost = "&".file_get_contents("php://input"); while(list($key,$value)= each($data)) { $pos = preg_match_all("/&".$key."=([^&]*)/i",$rawpost, $regs, PREG_PATTERN_ORDER); if((!is_array($value)) && ($pos > 1)) { $qform[$key] = array(); for($i = 0; $i < $pos; $i++) { $qform[$key][$i] = urldecode($regs[1][$i]); } } else { $qform[$key] = $value; } } return $qform; } // --- MAIN $_POST = repairPost($_POST); ?> The function will check every field in the $_POST with the raw post data and rebuild the arrays that got lost. --was-- To handle forms with or without [] you can do something like this: function repairPost($data) { // combine rawpost and $_POST ($data) to rebuild broken arrays in $_POST $rawpost = "&".file_get_contents("php://input"); while(list($key,$value)= each($data)) { $pos = preg_match_all("/&".$key."=([^&]*)/i",$rawpost, $regs, PREG_PATTERN_ORDER); if((!is_array($value)) && ($pos > 1)) { $qform[$key] = array(); for($i = 0; $i < $pos; $i++) { $qform[$key][$i] = urldecode($regs[1][$i]); } } else { $qform[$key] = $value; } } return $qform; } // --- MAIN $_POST = repairPost($_POST); The function will check every field in the $_POST with the raw post data and rebuild the arrays that got lost. http://php.net/manual/en/language.variables.external.php

« previous php.notes (#177703) next »