Home > Archive > PHP Language > October 2006 > help with useForm FormBuilder [PEAR]
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 |
help with useForm FormBuilder [PEAR]
|
|
| Lex Luthor 2006-10-12, 6:59 pm |
|
Thank you for your answer, I've resolved my first problem (That's "modiyfing
two tables with only one form, this is the way "
code:
<?php
require_once('DB/DataObject/FormBuilder.php');
require_once("PEAR.php");
define("DB_DATAOBJECT_NO_OVERLOAD",true); /* This is needed for some buggy
versions of PHP4 */
require_once("DB/DataObject.php");
$options = & PEAR::getStaticProperty('DB_DataObject',
'options');
// the simple examples use parse_ini_file, which is fast and efficient.
// however you could as easily use wddx, xml or your own configuration
array.
$config = parse_ini_file('dataObject.ini',TRUE);
// because PEAR::getstaticProperty was called with and & (get by reference)
// this will actually set the variable inside that method (a quasi static
variable)
$options = $config['DB_DataObject'];
////////////////////////////////////////////////////////////////////////////////////////////////////
DB_DataObject::debugLevel(1);
$first_table =& DB_DataObject::factory('tbl_menu_sx');
$first_table->fb_createSubmit = false;
$first_table->get(1);
$first_build =& DB_DataObject_FormBuilder::create($first
_table);
//$first_build->elementNamePrefix = 'formOne';
$first_form = $first_build->getForm();
$second_table = DB_DataObject::factory('tbl_menu_sx_lang
');
//$second_table->joinAdd($first_table); // add the product_image connectoin
$first_table->joinAdd($second_table); // add the product_image connectoin
$second_table->id_tbl_menu_sx=1;
$second_table->id_tbl_lingua=4;
$second_table->find();
$second_table->fetch();
$second_build =& DB_DataObject_FormBuilder::create($secon
d_table);
$second_build->elementNamePrefix = 'formTwo';
$second_build->useForm($first_form,false);
$second_form = $second_build->getForm();
if ($first_form->validate() && $second_form->validate()) {
echo "[".$first_form->process(array(&$first_build,'processForm'),
false)."]";
$second_table->id_tbl_menu_sx = $first_table->id;
$second_table->id_tbl_lingua = 4;
echo "[".$second_form->process(array(&$second_build,'processForm'),
false)."]";
$first_form->freeze();
}
print $second_form->toHTML();
?>
adding this line
$second_table->fetch();
and
if ($first_form->validate() && $second_form->validate()) {
echo "[".$first_form->process(array(&$first_build,'processForm'),
false)."]";
$second_table->id_tbl_menu_sx = $first_table->id;
$second_table->id_tbl_lingua = 4;
echo "[".$second_form->process(array(&$second_build,'processForm'),
false)."]";
$first_form->freeze();
}
Now I' ve another problem, I should have a field that save a list as
1,5,11,57 but in the same time it could show many checkboxes. I'm trying to
modify this code:
code:
<?php
class DataObjects_Tbl_menu_sx extends DB_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
public $__table = 'tbl_menu_sx'; // table name
public $id; // int(11) not_null
primary_key unique_key auto_increment
public $pub; // int(1) unsigned
public $nome; // string(50)
public $id_padre; // int(11) unsigned
public $checkbox_intention; // string(100)
public $posizione; // int(11)
public $checkbox_tbl_gruppi; // string(200)
public $checkbox_tbl_service; // string(200)
public $img; // string(100)
public $extra_link; // string(200)
/* Static get */
function staticGet($k,$v=NULL) { return
DB_DataObject::staticGet('DataObjects_Tb
l_menu_sx',$k,$v); }
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
//var $fb_hidePrimaryKey=false;
///*
function preGenerateForm(&$fb) {
$box=array();
$box[]=&
HTML_QuickForm::createElement('advcheckb
ox','checkbox_intention',null,
'0',null,'0');
$box[]=&
HTML_QuickForm::createElement('advcheckb
ox','checkbox_intention',null,
'1',null,'1');
$box[]=&
HTML_QuickForm::createElement('advcheckb
ox','checkbox_intention',null,
'2',null,'2');
$this->fb_preDefElements['checkbox_intention'] = $box;
}
}
I hope that you could help me, thank you very much
| |
| Lex Luthor 2006-10-17, 3:56 am |
| > marco schrieb:
>
> Hi Marco,
>
> I read your code and your description, and I am still not sure I
> understand what you want to achieve. Please try to rephrase.
>
> If your problem is that the elements are not being properly grouped
> together, try to put the array of elements into a QuickForm group:
>
> $group =& new HTML_QuickForm_group('checkbox_intention
', 'Intention',
> $box);
> $this->fb_preDefElements['checkbox_intention'] =& $group;
>
> See also:
> http://pear.php.net/manual/en/packa...uickform.groups
>
> CU
> Markus
Hallo Marcus,
Thanks a lot for your availability,
i update my code so :
code:
function preGenerateForm() {
$box=array();
$box[]=&
HTML_QuickForm::createElement('advcheckb
ox','checkbox_intention',null,
'0',null,'0');
$box[]=&
HTML_QuickForm::createElement('advcheckb
ox','checkbox_intention',null,
'1',null,'1');
$box[]=&
HTML_QuickForm::createElement('advcheckb
ox','checkbox_intention',null,
'2',null,'2');
$group =& new HTML_QuickForm_group('checkbox_intention
', 'Intention',
$box);
$this->fb_preDefElements['checkbox_intention'] =& $group;
}
but it makes an error
[error]
Notice: Array to string conversion in /usr/share/php5/PEAR/DB/DataObject.php
on line 1218
[/error]
[input]
Intention 0 1 2
[/input]
even if i check 0 and 1 and 2 in output
[output]
Intention [ ]0 [ ]1 [x]2
[/output]
Your suggest is near to the correct code version but as you've seen up,
there's also some problemes, please help me another one
|
|
|
|
|