For Programmers: Free Programming Magazines  


Home > Archive > PHP Pear > May 2006 > FormBuilder help









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author FormBuilder help
Patrick Paul

2006-05-25, 4:00 am

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_descripti
on');
/// 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($descr
iption);
$cityBuilder =& DB_DataObject_FormBuilder::create($city)
;
$cityBuilder->elementNamePrefix = 'city';


$cityForm =& $cityBuilder->getForm();
$descriptionBuilder->elementNamePrefix = 'description';
$descriptionBuilder->useForm($cityForm);
$combinedForm =& $descriptionBuilder->getForm();

/// 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( );
*?>*


Any help would be welcome.

Thank you,

Patrick
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com