PHP Classes

Possible bug in AddLabelPart function

Recommend this page to a friend!

      PHP Forms Class with HTML Generator and JavaScript Validation  >  PHP Forms Class with HTML Generator and JavaScript Validation package blog  >  Locating addresses on...  >  All threads  >  Possible bug in AddLabelPart function  >  (Un) Subscribe thread alerts  
Subject:Possible bug in AddLabelPart function
Summary:Custom inputs lose label atttributes
Messages:4
Author:Matías montes
Date:2006-12-28 18:09:05
Update:2006-12-29 02:53:04
 

  1. Possible bug in AddLabelPart function   Reply   Report abuse  
Picture of Matías montes Matías montes - 2006-12-28 18:09:05
The AddLabelPart function prepares an array caled $label and sets all label attributes in it either from the $arguments array or the $this->input[$for] array.

When passing a custom input as $for, the forms class calls the customclass AddLabelPart function using $label as the arguments array, but, in the line 1388, where the call is made, $label is not finished built up. That means that if you had set the ACCESSKEY, ID, STYLE or CLASS arguments in the $arguments array, they will not be set for the custom input as they are added to $label in later lines of code.

  2. Re: Possible bug in AddLabelPart function   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2006-12-28 19:14:21 - In reply to message 1 from Matías montes
The main forms class does not do that intentionally. It is up to the custom class to decide how to handle that.

If you want to assign the initial label and access key to a specific child input that your custom input creates, you should forward the label and access key values to that child input when the AddInput function of the custom input is called.

If you do not do it in your custom input, the plug-in base class implementation does it for you, as long as you have assigned the custom input class variable named focus_input to specify which child input gets the focus and be associaated with the label.

  3. Re: Possible bug in AddLabelPart function   Reply   Report abuse  
Picture of Matías montes Matías montes - 2006-12-29 00:55:18 - In reply to message 2 from Manuel Lemos
Hmm I'm not sure that's the expected behaviour.

I'll show you an example:

I made a fresh download of the class and edited the file: "/templates/form_linked_select_body.html.php"

changed line #8 to: <th><?php $form->AddLabelPart(array("CLASS"=>"myclass","FOR"=>"country")); ?></th>

The expected output is: <th><label for="p_country_select" accesskey="t" class="myclass">Coun<u>t</u>ry</label></th>

The output I actually got: <th><label for="p_country_select" accesskey="t">Coun<u>t</u>ry</label></th>

As you can see, it ignores my CLASS argument. This only happens with custom inputs.

BUT if instead of setting the class in the AddLabelPart function I set it in AddInput function as LabelCLASS argument, it works correctly.

I don't think this is expected to work this way. For what I've read in the documentation, the CLASS argument for the AddLabelPart function is not restricted to non-custom inputs.

And the same happens to every attribute assigned to $label after the if block in line #1386

  4. Re: Possible bug in AddLabelPart function   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2006-12-29 02:53:04 - In reply to message 3 from Matías montes
Oh, I though you were talking about something different.

I looked at it, and the class was not assigning some label parameters in the right places.

I rewrote it a bit and it now does what it was supposed to do correctly. I will upload it next week. For now, you may get the fixed version from the CVS repository.

Thank you for reporting.