Wednesday, May 16, 2007

PHP Tutorial

PHP Tutorial: This is a quick little tutorial on getting PHP form elements and making dynamic textboxes and mapping their values...

Getting the value of a form element using PHP
Hah! Simple. Depending on your form post method…

$fieldname = $_GET[fieldname];
Or
$fieldname = $_POST[fieldname];

Dynamic Textbox Arrays with PHP

input name="field_values[]" id=" field_values[]" size="5" maxlength="5" type="text"
input name="field_name[]" id="field_name[]" value="fieldname" type="hidden"

Let me explain what’s going on here. I am taking field values and making a hidden array of the field names they belong to:

Field_name=> Field1: [ textbox ] <= field_value Field2: [ textbox ] Field3: [ textbox ] On another page I want to go through those and insert values according to what value I had for each field. This builds an indexed array of values and the field that they map to. Now I use a little array function array_combine()

$combine = array_combine($_GET[fieldname],$_GET[field_values];

This builds an array like $combine[field_name][field_value]

Now I can reference the value that belongs to a particular field.

Hope you like this. It was pretty much my first attempt at a tutorial. I will get better.


Brian J. has been involved in web design since 1997. He is the founder of True Vision Computer Services, Inc. His recent focus has been on web applications and information systems development.

No comments: