Zend - The PHP Company




Forms

Add Code


array to hidden fields  

Type: application
Added by: robF
Entered: 19/06/2000
Last modified: 09/12/2010
Rating: **** (8 votes)
Views: 19455
takes a multidimensional array and puts all the elements into HTML hidden input types so data can be carried through to another page


<?php
function array_to_hidden($array$carry "data") {

    
/* feed it a multidimensional array and it goes right down putting every
     * non-blank element of every sub-array into a HIDDEN field of an HTML
     * FORM. The second argument should be the name of the variable
     *  you've passed */

    
while(list($name$value) = each($array)) {

        if (
is_array($value)):
            
array_to_hidden($value"${carry}[$name]");

        
/* uncomment the "elseif" if you don't want fields with blank values to be
         * passed along. (don't forget to comment out the else of course!) */

        //elseif (!ereg("^[ nt]*$", $value)):
        
else:
            echo 
"n<INPUT TYPE="hidden" NAME="${carry}[$name]" ",
            
"VALUE="$value">";
        endif;

    }



?>


Usage Example


See the example


Rate This Script





Search



This Category All Categories