CForm without form tag

everytime i get to use renderBody() with cform i get this error:




Fatal error: Call to a member function error() on a non-object in C:\Program Files (x86)\EasyPHP-5.3.2i\www\yii-1.1.5\framework\web\form\CFormInputElement.php on line 212



what makes "getActiveFormWidget()" return null when using renderBody() instead of render();


public function renderError()

	{

		$parent=$this->getParent();

		return $parent->getActiveFormWidget()->error($parent->getModel(), $this->name, $this->errorOptions);

	}

Urgentl help

If I’m not mistaken, you are suggesting, that there is an error in yii core files, however the error message you provided would rather suggest that it is in your own code. Are 100% sure that you are calling renderBody() on a variable being true object and being a CForm instance? Maybe you made a typo somewhere. Tried to use var_dump or print_r on this variable to see, what it actually is?

yes dude




                        $form = new CForm(

                        array(

                        'showErrorSummary'=>false, 

                        'elements'=>array(

                        'email'=>array('type'=>'text','maxlength'=>200,),

                        'address'=>array('type'=>'text','maxlength'=>50,),

                        'addressDet'=>array('type'=>'textarea','maxlength'=>50,),

                        'npa'=>array('type'=>'text','maxlength'=>50,),

                        'localite'=>array('type'=>'text','maxlength'=>50,),

                        'telFixe'=>array('type'=>'text','maxlength'=>50,),

                        'telFax'=>array('type'=>'text','maxlength'=>200,),

                        'telMobile'=>array('type'=>'text','maxlength'=>50,),

                        'horaire'=>array('type'=>'text','maxlength'=>50,),

                        'desc'=>array('type'=>'textarea','maxlength'=>50,),

                        'aboutUs'=>array('type'=>'textarea','maxlength'=>50,),

                        'feeter'=>array('type'=>'textarea','maxlength'=>50,),        


                        ) ,

                        ),

                        $this->member->profile);

                        print_r($form);

                      //  echo $form->renderBody();






and print_r($form) shows

    CForm Object

(

    [title] => 

    [description] => 

    [method] => post

    [action] => 

    [inputElementClass] => CFormInputElement

    [buttonElementClass] => CFormButtonElement

    [attributes] => Array

        (

        )


    [showErrorSummary] => 

    [activeForm] => Array

        (

            [class] => CActiveForm

        )


    [_model:CForm:private] => Profile Object

        (

            [_marquesList:Profile:private] => 

            [_tagsList:Profile:private] => 

            [_md:CActiveRecord:private] => CActiveRecordMetaData Object

                (

                    [tableSchema] => CMysqlTableSchema Object

                        (

                            [schemaName] => 

                            [name] => tb_profiles

                            [rawName] => `tb_profiles`

                            [primaryKey] => idProfile

                            [sequenceName] => 

                            [foreignKeys] => Array

                                (

                                    [idMember] => Array

                                        (

                                            [0] => tb_members

                                            [1] => idMember

                                        )


                                )


                            [columns] => Array

                                (

                                    [idProfile] => CMysqlColumnSchema Object

                                        (

                                            [name] => idProfile

                                            [rawName] => `idProfile`

                                            [allowNull] => 

                                            [dbType] => int(11)

                                            [type] => integer

                                            [defaultValue] => 

                                            [size] => 11

                                            [precision] => 11

                                            [scale] => 

                                            [isPrimaryKey] => 1

                                            [isForeignKey] => 

                                            [_e:CComponent:private] => 

                                            [_m:CComponent:private] => 

                                        )


                                    [idMember] => CMysqlColumnSchema Object

                                        (

                                            [name] => idMember

                                            [rawName] => `idMember`

                                            [allowNull] => 

                                            [dbType] => int(11)

                                            [type] => integer

                                            [defaultValue] => 

                                            [size] => 11

                                            [precision] => 11

                                            [scale] => 

                                            [isPrimaryKey] => 

                                            [isForeignKey] => 1

                                            [_e:CComponent:private] => 

                                            [_m:CComponent:private] => 

                                        )


                                    [tagsList] => CMysqlColumnSchema Object

                                        (

                                            [name] => tagsList

                                            [rawName] => `tagsList`

                                            [allowNull] => 

                                            [dbType] => text

                                            [type] => string

                                            [defaultValue] => 

                                            [size] => 

                                            [precision] => 

                                            [scale] => 

                                            [isPrimaryKey] => 

                                            [isForeignKey] => 

                                            [_e:CComponent:private] => 

                                            [_m:CComponent:private] => 

                                        )


                                    [email] => CMysqlColumnSchema Object

                                        (

                                            [name] => email

                                            [rawName] => `email`

                                            [allowNull] => 

                                            [dbType] => varchar(100)

                                            [type] => string

                                            [defaultValue] => 

                                            [size] => 100

                                            [precision] => 100

                                            [scale] => 

                                            [isPrimaryKey] => 

                                            [isForeignKey] => 

                                            [_e:CComponent:private] => 

                                            [_m:CComponent:private] => 

                                        )


                                    [address] => CMysqlColumnSchema Object

                                        (

                                            [name] => address

                                            [rawName] => `address`

                                            [allowNull] => 

                                            [dbType] => varchar(200)

                                            [type] => string

                                            [defaultValue] => 

                                            [size] => 200

                                            [precision] => 200

                                            [scale] => 

                                            [isPrimaryKey] => 

                                            [isForeignKey] => 

                                            [_e:CComponent:private] => 

                                            [_m:CComponent:private] => 

                                        )


                                    [addressDet] => CMysqlColumnSchema Object

                                        (

                                            [name] => addressDet

                                            [rawName] => `addressDet`

                                            [allowNull] => 

                                            [dbType] => text

                                            [type] => string

                                            [defaultValue] => 

                                            [size] => 

                                            [precision] => 

                                            [scale] => 

                                            [isPrimaryKey] => 

                                            [isForeignKey] => 

                                            [_e:CComponent:private] => 

                                            [_m:CComponent:private] => 

                                        )


                                    [npa] => CMysqlColumnSchema Object

                                        (

                                            [name] => npa

                                            [rawName] => `npa`

                                            [allowNull] => 

                                            [dbType] => varchar(10)

                                            [type] => string

                                            [defaultValue] => 

                                            [size] => 10

                                            [precision] => 10

                                            [scale] => 

                                            [isPrimaryKey] => 

                                            [isForeignKey] => 

                                            [_e:CComponent:private] => 

                                            [_m:CComponent:private] => 

                                        )


                                    [localite] => CMysqlColumnSchema Object

                                        (

                                            [name] => localite

                                            [rawName] => `localite`

                                            [allowNull] => 

                                            [dbType] => varchar(50)

                                            [type] => string

                                            [defaultValue] => 

                                            [size] => 50

                                            [precision] => 50

                                            [scale] => 

                                            [isPrimaryKey] => 

                                            [isForeignKey] => 

                                            [_e:CComponent:private] => 

                                            [_m:CComponent:private] => 

                                        )


                                    [telFixe] => CMysqlColumnSchema Object

                                        (

                                            [name] => telFixe

                                            [rawName] => `telFixe`

                                            [allowNull] => 

                                            [dbType] => varchar(50)

                                            [type] => string

                                            [defaultValue] => 

                                            [size] => 50

                                            [precision] => 50

                                            [scale] => 

                                            [isPrimaryKey] => 

                                            [isForeignKey] => 

                                            [_e:CComponent:private] => 

                                            [_m:CComponent:private] => 

                                        )

etc etc



i hope quiang will help me!

i just need to use cform as a manner to avoid writing lot of codes…

That’s Qiang, not Quiang! :]

If you are 100% sure that this is a bug, then you have to open a bug ticket (you need a Google accout to do that).

I checked a bit the source of CForm…




public function getActiveFormWidget()

{

 	if($this->_activeForm!==null)

 		return $this->_activeForm;

 	else

 		return $this->getRoot()->_activeForm;

}



Note that when using render()… it calls renderBegin() that in turn sets $this->:activeForm (CForm.php line 398)


$this->_activeForm=$this->getOwner()->beginWidget($class, $options);

Could be that this is missing when you use directly renderBody() ?

If that is so… try to call even renderBegin() and renderEnd() but do not echo the result like




$form->renderBegin(); // do not echo

echo $form->renderBody();

$form->renderEnd(); // do not echo



thankkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkks many many m Mdomda

dude u have found the problem.

it works like a sharm. But i think that ur solution is a turnarround of the problem, i guess renderBody should work without a need of renderBegin and renderend otherwise, renderbody must be a private method that has to be overrided by a public one that will include in its definition renderbegin/end…

I hope that this will be taken in consideration in future updates!!!

cheers dude