help with useForm FormBuilder [PEAR]

This is a discussion on help with useForm FormBuilder [PEAR] within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Thank you for your answer, I've resolved my first problem (That's "modiyfing two tables with only one ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-12-2006
Lex Luthor
 
Posts: n/a
Default help with useForm FormBuilder [PEAR]


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($second_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_Tbl_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('advcheckbox','checkbox_intention',null,
'0',null,'0');
$box[]=&
HTML_QuickForm::createElement('advcheckbox','checkbox_intention',null,
'1',null,'1');
$box[]=&
HTML_QuickForm::createElement('advcheckbox','checkbox_intention',null,
'2',null,'2');
$this->fb_preDefElements['checkbox_intention'] = $box;
}
}
I hope that you could help me, thank you very much


Reply With Quote
  #2 (permalink)  
Old 10-17-2006
Lex Luthor
 
Posts: n/a
Default Re: help with useForm FormBuilder [PEAR]

> marco schrieb:
>>
Code:
>> function preGenerateForm()
>> {
>> $this->fb_preDefElements['alive'] =
>> HTML_QuickForm::
>>  createElement('advcheckbox','alive','Ali
>> ve',null,null,$this->alive);
>> }
>>
>> this code generate a only one checkbox..
>> i would like to generate a list of checkbox so i tryed
Code:
>> function preGenerateForm(&$fb) {    $box=array();    $box[]=&
>> HTML_QuickForm::createElement('advcheckbox','checkbox_intention',null,
>> '0',null,'0');     $box[]=&
>> HTML_QuickForm::createElement('advcheckbox','checkbox_intention',null,
>> '1',null,'1');     $box[]=&
>> HTML_QuickForm::createElement('advcheckbox','checkbox_intention',null,
>> '2',null,'2');     $this->fb_preDefElements['checkbox_intention'] =
>> $box;      }
>>
>> but this don't save correctly.. field called "checkbox_intention" is a
>> varchar(200) and a i would like
>> to save as a list
>> so if i generate []labelA []labelB []labelC []labelD and i check A,C
>> i save in my
>> field "valueA,ValueC"
>> please help me.. i just send my request of help in forum.. but nobody
>> answer me

>
> 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/packag...ickform.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('advcheckbox','checkbox_intention',null,
'0',null,'0');
$box[]=&
HTML_QuickForm::createElement('advcheckbox','checkbox_intention',null,
'1',null,'1');
$box[]=&
HTML_QuickForm::createElement('advcheckbox','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


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:50 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0