note 101825 added to reserved.variables.post

From: Date: Thu, 13 Jan 2011 02:08:43 +0000
Subject: note 101825 added to reserved.variables.post
Groups: php.notes 
Request: Send a blank email to php-notes+get-175694@lists.php.net to get a copy of this message
It seems like no one here has posted a function to handle multi-select boxes or checkbox groups in php $_POST If you need a dynamic way to get the POST values of a form when : 1] you need to build a SQL statement from a POST 2] multiple select options stored in same column 3] the form input fields names can be arbitrary I Use this nice little function to handle this requirement : <?php // save as myPOSTProcessor.php function getPost($pst){ foreach ($pst as $key => $value) { $v = $value; $k = $key; if(is_array($v)){ $z = implode(",",$v); $kv[] = array($k,$z); }else{ $kv[] = array($k,$v); } } return $kv; } if($_POST){ $arr = getPost($_POST); print_r($arr); } ?> +++++++++++ An example form that uses this : <form method="POST" name="form1" id="form1" action="myPOSTprocessor.php"> <input name="textfield" type="text" id="textfield" value="text" /> <textarea name="textarea" id="textarea" cols="45" rows="5">textarea</textarea> <input name="checkbox" type="checkbox" id="checkbox" checked="checked" /> <input name="checkboxu[]" type="checkbox" id="checkbox2" value="1" checked="checked" /> <input name="checkboxu[]" type="checkbox" id="checkbox3" value="2" checked="checked" /> <input name="checkboxu[]" type="checkbox" id="checkbox4" value="3" checked="checked" /> <input type="radio" name="radio" id="radio1" value="radio1" /> <input name="radio" type="radio" id="radio2" value="radio2" checked="checked" /> <input type="radio" name="radio" id="radio3" value="radio3" /> <select name="xselect[]" size="3" multiple="multiple" id="select"> <option value='11111' selected="selected">option 1</option> <option value='22222' >option 2</option> <option value='33333' selected="selected">option 3</option> </select> <input type="image" name="imageField" id="imageField" value="image" src="random.gif" /> <input type="submit" id="button" value="Submit" /> </form> ---- Server IP: 64.71.164.2 Probable Submitter: 24.16.71.129 ---- Manual Page -- http://www.php.net/manual/en/reserved.variables.post.php Edit -- https://master.php.net/note/edit/101825 Del: integrated -- https://master.php.net/note/delete/101825/integrated Del: useless -- https://master.php.net/note/delete/101825/useless Del: bad code -- https://master.php.net/note/delete/101825/bad+code Del: spam -- https://master.php.net/note/delete/101825/spam Del: non-english -- https://master.php.net/note/delete/101825/non-english Del: in docs -- https://master.php.net/note/delete/101825/in+docs Del: other reasons-- https://master.php.net/note/delete/101825 Reject -- https://master.php.net/note/reject/101825 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#175694) next »