Re: FormBuilder help

From: Date: Thu, 25 May 2006 05:54:11 +0000
Subject: Re: FormBuilder help
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-24147@lists.php.net to get a copy of this message
On 5/24/06, Patrick Paul <ppaul_apache@yahoo.ca> wrote:
Hi, Here is what I am attempting to do using FormBuilder. I have two tables, cities (cities_id INT auto_increment) and cities_description (cities_id, languages_id, cities_name). I want FormBuilder to make a form that will add a new entry to cities and cities_description. The trick I'm trying to use is to have two forms in one, as in the rapidprototyping-kr-1.pdf. What I would like it to do is create a new entry in cities first, and use the resulting cities_id to create the new entry in cities_description. Here is my code : <?php $description = DB_DataObject::factory('cities_description'); /// this is because (cities_id,languages_id) is the primary key/ $description->keys('id'); $city = DB_DataObject::factory('cities'); $city->createSubmit=*false*; $descriptionBuilder =& DB_DataObject_FormBuilder::create($description); $cityBuilder =& DB_DataObject_FormBuilder::create($city); $cityBuilder->elementNamePrefix = 'city'; $cityForm =& $cityBuilder->getForm(); $descriptionBuilder->elementNamePrefix = 'description'; $descriptionBuilder->useForm($cityForm); $combinedForm =& $descriptionBuilder->getForm();
Yep, the above code is correct for combining 2 FB forms into one form.
/// Create a FormBuilder for the post/ $formBuilder = &DB_DataObject_FormBuilder::create( $description ); /// Actually fetch the Form/ $form = &$formBuilder->getForm( ); /// If we validate, then we process it here/ if( $form->validate( ) ) {
    $form->process( array( &$formBuilder, 'processForm' ), *false* );
    /// Redirect/
    header( "Location: http://" . $_SERVER[ 'HTTP_HOST' ] .
    dirname( $_SERVER[ 'PHP_SELF' ] ) . "/test4.php" );
} $form->display( );
But then you negate all of that here. You're using a description-only form from my last comment to here. That's not what you want. Instead of using $form, use $combinedForm. Then, to process, call $form->process with *both* of the formBuilder instances. First the city one, then the description one. Make sure to set the city ID in the description DO before you process it, though.
*?>* Any help would be welcome. Thank you, Patrick -- PEAR General Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- Justin Patrin

« previous php.pear.general (#24147) next »