Re: FormBuilder -- generating one form from multiple forms
| From: | Justin Patrin | Date: | Sun, 18 Sep 2005 18:32:54 +0000 |
| Subject: | Re: FormBuilder -- generating one form from multiple forms | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-21029@lists.php.net to get a copy of this message | ||
On 9/18/05, wesley@furgiuele.net <wesley@furgiuele.net> wrote:
> I am trying to set up FormBuilder to generate one form from multiple forms
> -- so each row in my database table appears as a row in the form, allowing
> for a quick review/edit of the whole table.
>
> Here's what I have:
>
> // Get all primary keys for the table.
> $primary_keys = $db->getCol( "SELECT Record_ID FROM $db_table ORDER BY
> Record_ID ASC" );
>
> // Get all the DataObjects and FormBuilder objects first.
> foreach( $primary_keys AS $key ) {
> $dataobject[ $key ] =& DB_DataObject::factory( $db_table );
> $dataobject[ $key ]->get( $key );
First off, this is a *horrible* way to do this. Why select only the PK first?
$do =& DB_DataObject::factory($db_table);
$do->orderBy('RECORD_ID ASC');
if ($do->find()) {
while (do->fetch()) {
$dataobject[ $key ] =& clone($do);
>
> $formbuilder[ $key ] =& DB_DataObject_FormBuilder::create( $dataobject[
> $key ] );
> $formbuilder[ $key ]->elementNamePrefix = $key."__";
> }
>
> // Create the form
> $form = $formbuilder[ 0 ]->getForm();
>
> // Everything fine so far. I can test it here and it displays form for
> // the first row in the database table.
>
> // Add all the other rows to this form.
> for( $i = 1; $i < count( formbuilder ); $i++ ) {
> $formbuilder[ $i ]->useForm( $form );
> $formbuilder[ $i ]->getForm();
> }
>
> $form->display();
>
> This, unfortunately, causes a form to be generated for each row. I see, in
> this case, 150 forms on the page, each with their own submit button,
> rather than one form with 150 groups of elements, all having only one
> submit button. All the elements are, however, correctly names with the
> prefix.
>
> [form header]
> [field1 label]: [001__text_field_1]
> [field2 label]: [001__text_field_2]
> [submit button]
>
> [form header]
> [field1 label]: [002__text_field_1]
> [field2 label]: [002__text_field_2]
> [submit button]
>
> and so on, for 150 "rows".
>
> At this point, I'm not setting any other options or trying anything with
> any formatting. -- I'm just trying to keep it simple. So what am I
> missing?
>
No, that's still one form. It just happens to hav 150 submit buttons.
Use the createSubmit FB option to turn that off then add your own at
the end.
--
Justin Patrin