spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / php_forms2 / 1 current pageTo page 2To page 3To page 4
[next]

Sr. Web Developer
Professional Technical Resources
US-OR-Portland

Justtechjobs.com Post A Job | Post A Resume
Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

How to Interact with Web Forms. Part 2

Excerpted from Chapter 4: Interacting with Web Forms in the PHP Phrasebook by Christian Wenz. ISBN 0672328178, Copyright © 2005. Used with the permission of Sams Publishing.

Preselecting Multiple Selection Lists

When it comes to prefilling form elements, multiple selection lists are the most difficult ones to implement. This is because in $_GET or $_POST, you have an array of chosen options; so you cannot just compare strings, but you have to search for the specified value in the array. Luckily, PHP offers something suitable in the form of the in_array() function. So, the effort required is not much more than with the other form elements: If the current value is in $_GET/$_POST, print out the selected attribute.

However, the HTML form must be specially preparedto allow PHP to access the data from the multiple selection list:The value of the name attribute has to end with [], hinting to PHP that it should expect an array of values, not just a string value. Accessing the list data, however, can still be done using $_GET[‘listname‘]/$_POST[‘listname‘] and not $_GET[‘listname[]‘]/$_POST[‘listname[]‘], as shown in the preceding code.

If you want to prefill the list with data from the cookie, you just have to use the well-known file getFormData.inc.php from the previous phrases.

It contains two additional functions that return an array instead of a string.

These functions return an array for multiple lists that you can use as you did in select-multiple.php.

Processing Graphical Submit Buttons

Graphical Submit buttons (<input type=”image” />) are not only a nice way to spicen up the layout of the form, but they also offer a nice feature:The browser submits the x and the y coordinates of the mouse pointer when clicking on the button. In PHP, this happens by appending _x and _y to the name attribute of the button and writing this into $_GET or $_POST.The preceding code evaluates this information.

home / programming / php_forms2 / 1 current pageTo page 2To page 3To page 4
[next]

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Working with the DOM Stylesheets Collection · Administering RBAC in PHP 5 CMS Framework · xref: Automatic Cross Referencing Script
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Combine BottomCount() with Other MDX Functions to Add Sophistication · Creating a Daemon with Python · The Coming Voice-over-WiMAX Revolution

Created: March 27, 2003
Revised: January 23, 2006

URL: http://webreference.com/programming/php_forms2/1