PHP Classes

Embedding inputs into the label field

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  >  How to Show Google Ma...  >  All threads  >  Embedding inputs into the label field  >  (Un) Subscribe thread alerts  
Subject:Embedding inputs into the label field
Summary:Is there a way to embed input fields inside of the label tags?
Messages:6
Author:Philip Hewitt
Date:2010-01-30 18:53:40
Update:2010-01-31 18:08:55
 

  1. Embedding inputs into the label field   Reply   Report abuse  
Picture of Philip Hewitt Philip Hewitt - 2010-01-30 18:53:40
I want to be able to embed all types input fields inside of their label tags as seen below. This will allow for some fancy CSS manipulation for better horizontal layouts. Is this possible with this class?

<fieldset>
<legend>
Name
</legend>
<label for="firstName1">
First name
<input id="firstName1" name="firstName1" type="text" value="First name" />
</label>
<label for="lastName1">
Last name
<input id="lastName1" name="lastName1" type="text" value="Last name" />
</label>
</fieldset>

  2. Re: Embedding inputs into the label field   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2010-01-30 19:41:26 - In reply to message 1 from Philip Hewitt
You can use the Format property to define presentation template of the date inputs.

  3. Re: Embedding inputs into the label field   Reply   Report abuse  
Picture of Philip Hewitt Philip Hewitt - 2010-01-30 22:50:53 - In reply to message 2 from Manuel Lemos
Forgive me Manual, but I don't understand could you post an example? I know how to use "FORMAT" to modify the way a data looks ie "{month} / {day} / {year}", but I am looking to have the class embed the $form->AddInputPart("lname"); inside of the <label> tag that is generated by $form->AddLabelPart(array("FOR"=>"lname"));

$form->AddInput(array(
"TYPE"=>"text",
"NAME"=>"lname",
"ID"=>"lname",
"SIZE"=>20,
"FORMAT"=> ????????????
"ValidateAsNotEmpty"=>1,
"ValidateAsNotEmptyErrorMessage"=>"Please enter your last name?",
"LABEL"=>"<u>L</u>ast Name",
"ACCESSKEY"=>"L"
));

  4. Re: Embedding inputs into the label field   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2010-01-30 23:26:50 - In reply to message 3 from Philip Hewitt
You can set the Format parameters to something like:

"<fieldset>
<legend>
Name
</legend>
<label for="p_date_year">
First name
{year}
</label>
</legend>
<label for="p_date_month">
Month
{month}
</label>
</legend>
<label for="p_date_day">
Day
{day}
</label>
</fieldset>"

  5. Re: Embedding inputs into the label field   Reply   Report abuse  
Picture of Philip Hewitt Philip Hewitt - 2010-01-31 14:01:20 - In reply to message 4 from Manuel Lemos
So I did the following and nothing changed.

$form->AddInput(array(
"TYPE"=>"text",
"NAME"=>"lname",
"ID"=>"lname",
"SIZE"=>20,

"FORMAT"=>"<label for="p_lname" accesskey="L">Last Name{lname}</label>",

"ValidateAsNotEmpty"=>1,
"ValidateAsNotEmptyErrorMessage"=>"Please enter your last name?",
"LABEL"=>"<u>L</u>ast Name",
"ACCESSKEY"=>"L"
));

My HTML output was still incorrect as seen below.

<label for="lname" accesskey="L"><u>L</u>ast Name</label><input type="text" name="lname" size="20" id="lname" accesskey="L" />

I then tried removing
"LABEL"=>"<u>L</u>ast Name",
"ACCESSKEY"=>"L"

But all that got me was an error "Notice: salutation: it was not specified a valid label". So I guess I'm stuck using the old technique of HTML Tables?

  6. Re: Embedding inputs into the label field   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2010-01-31 18:08:55 - In reply to message 5 from Philip Hewitt
The Format parameter is only considered for date inputs. Also it is case sensitive. So it is Format, not FORMAT.

For other types of inputs you need to call AddDataPart before and after AddInputPart with whatever HTML you want to show before and after the input.