Re: passing array in form HELP!

From: Date: Mon, 04 Dec 2000 22:01:27 +0000
Subject: Re: passing array in form HELP!
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-28649@lists.php.net to get a copy of this message
well, of course you can't pass it like this. you can either echo "<input type='hidden' name='info' value='".serialize( $info )."'>" ; or foreach( $info as $k => $v ) { echo echo "<input type='hidden' name='info_$k' value='$v'>" ; } ; and then function create_array( $values , $name ) { $retval = array() ; $nl = strlen( $name ) ; foreach( $values as $k => $v ) { if( $name == substr( $k , 0 , $nl ) ) { $retval[ substr( $k , $nl ) ] = $v ; } ; } ; return $retval ; } ; $info = create_array( $HTTP_POST_VARS , 'info_' ) ; or function create_array( $values , $name ) { $retval = array() ; $nl = strlen( $name ) ; foreach( $values as $k => $v ) { if( $name == substr( $k , 0 , $nl ) ) { $retval[ substr( $k , $nl + 1 ) ] = $v ; } ; } ; $GLOBALS[ $name ] = $retval ; return sizeof( $retval ) ; } ; if( $x = create_array( $HTTP_POST_VARS , 'info' ) { echo "created array called \$info of $x elements in the global namespace" ; } ; At 22:13 4.12. 2000, John Hanson wrote the following: -------------------------------------------------------------- >I can not get an array to pass in a form as a hidden variable! It allways returns a string. >I want to pass additional info in a form (not info in the form itself) with POST method >This is what I'm doing: > >IN FORM------> >$info=array("first_name"=>"John", >"middle_init"=>"R", >"last_name"=>"Hanson"); > >echo "<input type=\"hidden\" name=\"info\" >value=\"".$info."\">"; > >IN 2nd PAGE----> >$info=$HTTP_POST_VARS["info"]; > >THIS LINE; >echo "info is=>".gettype($info); > >PRINTS ---> >info is=>sring > >WHY IS IT A STRING?? ------end of quote------ ____________________________________________________________ Cynic: A member of a group of ancient Greek philosophers who taught that virtue constitutes happiness and that self control is the essential part of virtue. cynic@mail.cz ICQ: 2808 2505

« previous php.general (#28649) next »