This has jump started me.  How do I grab only certain variables, for
example, only vars named "doh," or, better yet, only vars containing
"doh?"  I have check box vars named 4-1, 4-2, 4-3, 4-4, etc., and I wish
to stick them together in a string, but only those vars, no others.

Is there a smarter way to do this?



>>> Erik Price <[EMAIL PROTECTED]> 04/10/02 04:27PM >>>

On Wednesday, April 10, 2002, at 04:12  PM, ROBERT MCPEAK wrote:

> I need some help with html forms.  I primer on html forms and
> is much needed.  Anybody have some code snipets to share?

Sure.  I was just working on a little code snippet that grabs all the 
GET variables (you could do the same with the POST variables) and
them in a hidden form field.  Originally I was using 
$_SERVER['QUERYSTRING'], which you would think does the same thing, but

the latter actually points to the actual querystring, including empty 
variables.  This script will look only for the GET variables that have

$return_path_arr = array();  // initialize the array to temporarily 
store GET vars
$return_path_str = "";  // initialize the string to store GET vars

// this loops through all GET vars and assigns their names to
// and their values to $getvarvalue in each iteration of the loop
foreach ($_GET as $getvarname => $getvarvalue) {

     // create the name-value pair
     $return_path_arr[] = $getvarname . "=" . $getvarvalue;

// take each name-value pair and implode it into one big string,
// with each pair separated by '&'
$return_path_str = implode("&", $return_path_arr);

// later, I stick this string into a hidden form field so that I have
// my own custom "back" button where I will need it
echo "<input type=\"hidden\" name=\"returnpath\" 
value=\"$return_path_str\" />";

This exact same trick can be used to grab all the POST vars and print 
them with commas in between, just substitute a comma for the "&" sign
the implode() function and instead of looping through the $_GET array,

loop through the $_POST array.

Any questions, feel free to ask.

> I'm getting acquainted with $HTTP_POST_VARS but need some help in
> accomplishing a couple of things.
> I'd like to collect all "checkbox" input variables and stick them
> together in a comma delimited string.
> I'd also like to display the names and values of the all posted
> variables.
> In another language I'm familiar with, this looks like:
> [formvariables name=thevarname][name]=[value]<BR>[/formvariables]
> For passed checkbox input var doh, where values were blah and bleck,
> the above code would display:
> doh=blah
> doh=bleck
> How do I do this with php?

Make the "name" attribute of each checkbox <input> tag look like this: 

"doh[]".  The brackets tell PHP to store each value into an array named




Erik Price
Web Developer Temp
Media Lab, H.H. Brown

PHP General Mailing List (
To unsubscribe, visit:

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to