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 variables
> 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 stores 
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 a 
value:

$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 $getvarname
// 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 in 
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 
$doh.



Erik




----

Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to