Re: SELECT tags in PHP, addressing selected options

From: Date: Thu, 28 Sep 2000 21:55:13 +0000
Subject: Re: SELECT tags in PHP, addressing selected options
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-17968@lists.php.net to get a copy of this message
I will be releasing a my entire HTML Forms package soon if there is engough interest, but this function should do what you want. Please email me off the list if anyone is interested in my complete package. You pass it an array keyed with the value and description. The name is the NAME= HTML element. The value_selected is the name of the element that is in the previous array that you want highlighted. The size is the size of the select and the multiple is a flag as to whether or not use multiple options. To use it do this: print html_select('variable_name', $the_prebuilt_array, 'option1', 1, FALSE); This is, of course, Copyright 2000 Jeremy Brand: /** CODE BEGINS HERE **/ function html_select($name, $value_description_array, $value_selected='', $size=1, $multiple=FALSE) { /** Copyright 2000 Jeremy Brand **/ $num_elements = count($value_description_array); if ($size > $num_elements) $size = $num_elements; $mul = ''; if ($multiple) $mul = ' multiple'; $buf = '<select name="' .htmlspecialchars($name). '" size="' .$size. '"' .$mul. '>' . "\n"; /** make sure tmp[0] exists and is NULL, ** needed for this to work corectly **/ $tmp[''] = ''; $tmp[$value_selected] = ' selected'; /** Using error_reporting() here is a ** hack to make sure printing out $tmp[unset] doesn't bitch. ** Doing it this way is much quicker than doing a compare each ** time through the loop **/ $orig_error = error_reporting(0); while(list($key, $val) = each($value_description_array)) $buf .= ' <option value="' .htmlspecialchars($key). '"' .$tmp[$key]. '>' .$val. "\n"; error_reporting($orig_error); unset($tmp); unset($orig_error); unset($mul); $buf .= '</select>'; return $buf; } /** CODE ENDS HERE **/ _______________________________________________________________________ GnuPG Fingerprint: 9F5E 95E0 1CC2 E054 84EA 6099 8ACD 9DBA D2C0 5EA9 _ http://www.JeremyBrand.com/Jeremy/Brand/Jeremy_Brand.html for more __ _ http://www.google.com/search?q=jeremy+brand __ On Thu, 28 Sep 2000, Liam Gibbs wrote: > Date: Thu, 28 Sep 2000 17:34:55 -0500 > From: Liam Gibbs <lgibbs@microlegend.com> > To: php-general@lists.php.net > Subject: [PHP] SELECT tags in PHP, addressing selected options > > I'm having a problem with PHP/HTML. My problem is this: > > I have a <SELECT NAME = "list" MULTIPLE> list box in an HTML form. In that, > obviously, users can select multiple choices. They click the submit button. The action for the form > is to submit it to a PHP page which will list all of the selected options, which are > <OPTION>Choice1</OPTION>. > > But how? I can't figure out how to address those selected options. Would it be $Choice1? > Should I include a NAME attribute? Does anyone know how to address these options? > > Liam Gibbs >

« previous php.general (#17968) next »