PHP Classes

very nice ... two suggestions

Recommend this page to a friend!

      Build Form Class  >  All threads  >  very nice ... two suggestions  >  (Un) Subscribe thread alerts  
Subject:very nice ... two suggestions
Summary:add tabindex and id attributes
Messages:5
Author:David Hyland
Date:2011-03-04 14:45:27
Update:2011-03-04 18:17:32
 

  1. very nice ... two suggestions   Reply   Report abuse  
Picture of David Hyland David Hyland - 2011-03-04 14:45:27
hey there. i really like this class and can see many uses for it. however i have two suggestions for completeness:

1) add an incrementing tabindex attribute into the fields in the order they are generated. this helps with usability.

2) add an id attribute to the fields (you could use the same value as 'name'). this is important as the 'for' attribute of <label> needs an ID. it's also useful for applying any javascript actions onto particular fields via jquery or the like.

cheers!

  2. Re: very nice ... two suggestions   Reply   Report abuse  
Picture of David Hyland David Hyland - 2011-03-04 16:01:43 - In reply to message 1 from David Hyland
one quick solution to adding tabindex could as follows:

1) add 'tabindex=#TABINDEX#' into each field html template

2) add the following function:

$tabindex = 1;
function incTabindex($matches){
global $tabindex;
$output = '';
foreach($matches as $match)
{
$output .= $tabindex;
$tabindex++;
}
return $output;
}

3) add this line just before the final form output:

$content = preg_replace_callback("/#TABINDEX#/", "incTabindex", $content);

  3. Re: very nice ... two suggestions   Reply   Report abuse  
Picture of razvan razvan - 2011-03-04 17:45:26 - In reply to message 2 from David Hyland
Thank you for your comments!

Yes the ID part I can do but it will be a small problem with the radio buttons (the name is always the same)
I think the ID for radio will be NAMEVALUE or something like that.
I'll think about it, it will be a problem if you use same name for a fieldset and a input field.

The ID right now, can be added using the $field_style ( array("ID" => "somename") )

And the tabindex I wanted to do but the problem was the order of the fields...
You know... you add the fields in some order, but if you use another order with the fieldsets, it won't work.
If your function works, I'll put it there along with your name.

Thanks again!

  4. Re: very nice ... two suggestions   Reply   Report abuse  
Picture of David Hyland David Hyland - 2011-03-04 17:54:47 - In reply to message 3 from razvan
hey there,

regarding the radio IDs you are of course right. the solution there would be to add an incremented integer to each field thereby retaining the same name with unique IDs

the tabindex function works perfectly as i've added into your class. adding it at the very end ensures that it increments correctly down through the generated code regardless of which fieldset comes first.

if you want i can send you my updated file for your reference.

cheers!

  5. Re: very nice ... two suggestions   Reply   Report abuse  
Picture of razvan razvan - 2011-03-04 18:17:32 - In reply to message 4 from David Hyland
yes please. moarte2[at]yahoo[dot]com

 
For more information send a message to info at phpclasses dot org.