Re: HTML_QuickForm setElementTemplate() question
| From: | Justin Patrin | Date: | Sat, 08 Apr 2006 05:26:32 +0000 |
| Subject: | Re: HTML_QuickForm setElementTemplate() question | ||
| References: | 1 2 3 4 5 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-23594@lists.php.net to get a copy of this message | ||
On 4/7/06, James Reinke <jreinke@cleversafe.com> wrote:
> Yeah, I can see how what I'm talking about isn't too specific. I tried to
> illustrate what I did in this .gif, I figure that's about the best way of
> illustrating this. Please take a look and let me know Justin, and thanks
> for your time, its much appreciated.
>
> For those who can't see the gif, here is the layout I'm trying to obtain:
>
> Heading1
> -->radio1
> -->radio2
> Heading2
> -->radio3
> -->radio4
> Heading3
> -->radio5
> -->radio6
>
> Submit
>
>
> All radios are named the same thing, and as you can see, each group of two
> radio buttons shares a heading (pulled from a db), a name (pulled from db)
> and their own unique 'value=xx' (also from the db).
>
> http://www.multitech-group.com/images/radiobuttons.gif
>
>
> If anybody has a workaround please let me know! Thanks.
>
So...when you create the radio buttons you put the value and display
text in the createElement or addElement call. You don't need a
template for that.
For the headings use a static element, as you mentioned before. This
is all easy enough to do in a loop.
$form = new HTML_QuickForm();
$sth = $db->query('SELECT value, text, heading FROM radioTable');
$oldHeading = '';
while ($row = $sth->fetchRow(DB_FETCHMODE_ASSOC)) {
if ($row['heading'] != $oldHeading) {
$oldHeading = $row['heading'];
$form->addElement('static', 'heading', $row['heading']);
}
$form->addElement('radio', 'radioGroup', '',
$row['heading'], $row['value']);
}
$sth->free();
> Jim
>
> ----- Original Message -----
> From: "Justin Patrin" <papercrane@gmail.com>
> To: "James Reinke" <jreinke@cleversafe.com>
> Cc: <pear-general@lists.php.net>
> Sent: Friday, April 07, 2006 10:53 PM
> Subject: Re: [PEAR] HTML_QuickForm setElementTemplate() question
>
>
> On 4/7/06, James Reinke <jreinke@cleversafe.com> wrote:
> > Justin,
> >
> > Thanks for the quick response. I only tried to use the
> > addElement('html','') as a last ditch effort to see if I could get the
> > formatting correct, (from what I understand 'static' is the correct way)
> > Anyways, I tried setting individual elements before using
> > setElementTemplate(), but the problem I run into, is because they are
> > radio
> > buttons, they all must be named the same thing (or else the end user is
> > allowed to select more than one radio button at a time). I neglected to
> > disclose this, but I did try this method earlier setting individual
> > elements. Is there any workaround for this? Please advise.
> >
>
> No, there's no direct workaround for that. But, as I said before, if
> you're using templates to set the names of radio buttons and such
> you're doing something wrong. Perhaps you should provide some code and
> specifics about what you're trying to do.
>
> >
> > ----- Original Message -----
> > From: "Justin Patrin" <papercrane@gmail.com>
> > To: <jreinke@cleversafe.com>
> > Cc: <pear-general@lists.php.net>
> > Sent: Friday, April 07, 2006 8:58 PM
> > Subject: Re: [PEAR] HTML_QuickForm setElementTemplate() question
> >
> >
> > On 4/7/06, jreinke@cleversafe.com <jreinke@cleversafe.com> wrote:
> > >
> > > Greetings all,
> > >
> > > First off, this list has been a tremendous help to my QuickForm
> > > experience. (Timothy Marsolais -- you helped me a ton)
> > >
> > > However, I seem to be having trouble solving this problem efficiently,
> > > and
> > > I was wondering if any of you have had similar experiences. My problem,
> > > is that I can not use the $renderer->setElementTemplate() function,
> > > because each of my elements contains different information. If you can
> > > imagine 3-4 different service plans displayed on a form, each with
> > > different labels/values and what not that I'm pulling interactively from
> > > the database.
> > >
> > > The problem is two fold. I try to insert the values in a few for loops
> > > using commands like $form->addElement('html',
> > > '<p>$whatever</p>'), but I
> > > find this just adds all the html to the beginning of the form (before
> > > the
> > > element is printed out), resulting in a correct formatting, but all of
> > > the
> > > radio buttons are naked at the bottom of the form. Then, when I try to
> > > create a new elementTemplate() for each of the 3-4 radio buttons, they
> > > only inherit the attributes from the last elementTemplate I made. I'm
> > > hoping theres something I can do for this situation, and would greatly
> > > appreciate any advise. Thanks again in advance!
> > >
> >
> > It's suggested that you don't use the html element. It injects HTML
> > directly into the output. Look at the resultant source and you'll see
> > it's not in TD tags.
> >
> > If you have no text for your radio elements you're creating the
> > elements incorrectly. Look closer at the constructors.
> >
> > Also, look closer at setElementTemplate. It's meant to set the overall
> > template for all of the elements *or* a template for each element. If
> > your elements are all named the same they'll get the same template.
> >
> > --
> > Justin Patrin
> >
> >
>
>
> --
> Justin Patrin
>
>
>
--
Justin Patrin