Recommend this page to a friend! |
|
![]() Hi,
It is my first time to use the smarty plugin for the forms generation class in my projects. However I get this error: Fatal error: Call to a member function AddDataPart() on a non-object in ../plugins/insert.formadddatapart.php on line 18. When I try to var_dump($tpl_vars['form']) it dumps an object. I would appreciate any help from you people. Regards, Ajowi
![]() It is hard to tell without seeing your code.
Maybe you are reassigning the template variable to something else that is not the form object.
![]() Hi Manuel,
Thanks for your reply. Here is the code. <?php include('../setup/smarty_setup.php'); /* * Include Smarty template prefilter plugin function * */ require("plugins/prefilter.form.php"); /* * Include form class code. */ require("../forms/forms.php"); /* * Create a form object. */ $form=new form_class; $form->NAME="company_form"; $form->METHOD="GET"; $form->ACTION=""; $form->ResubmitConfirmMessage="Are you sure you want to submit this form again?"; $form->OptionsSeparator="<br>\n"; /* * Output all validation errors. */ $form->ShowAllErrors=1; /* * CSS class for invalid inputs. * */ $form->InvalidCLASS='invalid'; /* * Define the form field properties even if they may not be displayed. */ $form->AddInput(array( "TYPE"=>"text", "NAME"=>"company_name", "ID"=>"company_name", "MAXLENGTH"=>100, "Capitalization"=>"lowercase", "ValidateAsNotEmpty"=>1, "ValidationErrorMessage"=>"Company name is required", "LABEL"=>"<u>C</u>ompany name", "ACCESSKEY"=>"C" )); $form->AddInput(array( "TYPE"=>"text", "NAME"=>"reg_number", "ID"=>"reg_number", "MAXLENGTH"=>100, "Capitalization"=>"lowercase", "ValidateAsNotEmpty"=>1, "ValidationErrorMessage"=>"Company registration number is required", "LABEL"=>"<u>R</u>egistration No.", "ACCESSKEY"=>"R" )); $form->AddInput(array( "TYPE"=>"hidden", "NAME"=>"doit", "VALUE"=>1 )); ............... /*I process form here normally */ $form->LoadInputValues($form->WasSubmitted("doit")); $verify=array(); if($form->WasSubmitted("doit")) { if(($error_message=$form->Validate($verify))=="") { $doit=1; } else { $doit=0; $error_message=HtmlEntities($error_message); } } else { $error_message=""; $doit=0; } if($doit) { $form->ReadOnly=1; } /* * I Create the Smarty engine object to process the form template first * */ $smarty=&new EicharTemplateEngine(); if($smarty->template_exists("company_form.tpl")) { $smarty->assign_by_ref("form",$form);/* I assign the object here*/ $smarty->assign("title","General Company Information"); $smarty->assign("error_message",$error_message); $smarty->assign_by_ref("verify",$verify); $smarty->assign("doit",$doit); $smarty->assign("mark","[Verify]"); $smarty->register_prefilter("smarty_prefilter_form"); $smarty->fetch("company_form.tpl"); $smarty->unregister_prefilter("smarty_prefilter_form"); } ........................ /* * I Output the form within a page using a Smarty page template */ if($smarty->template_exists("company_info.tpl")) { $onload=HtmlSpecialChars($form->PageLoad()); $smarty->assign("form", $form->FetchOutput()); $smarty->assign("title", "General Company Information"); $smarty->assign("onload", $onload); $smarty->assign('styles', '.invalid { border-color: #ff0000; background-color: #fff; }'); $smarty->display("company_info.tpl"); } ?> And here is the template. {include file="formerror.tpl"} <center><table summary="Form table" border="1" bgcolor="#c0c0c0" cellpadding="2" cellspacing="1"> <tr> <td bgcolor="#000080" style="border-style: none;"><font color="#ffffff"><b>{$title}</b></font></td> </tr> <tr> <td style="border-style: none"> <center><table summary="Input fields"> <tr> <th align="right">{label for="company_name"}:</th> <td>{input name="company_name"}</td> {if isset($verify.company_name)}<td>{$mark}</td> {/if} <th align="right">{label for="reg_number"}:</th> <td>{input name="reg_number"}</td> {if isset($verify.reg_number)}<td>{$mark}</td> {/if} </tr> ....................... Once again the error is caught in plugins/prefilter.form.php which I have not edited. Regards,
![]() I could not reproduce your error because you use a different Smarty class and you used a template file that you did not provide.
Anyway, it seems the problem may be caused by the line: $smarty->assign("form", $form->FetchOutput()); It reassigns the form template variable which would not be a problem if $smarty->unregister_prefilter("smarty_prefilter_form") was working. I don't know what changed Smarty class you are using but that may be the root of your problem. To avoid further problems, I suggest changing the form template variable to something like company_form and change your template too. Alternatively, since your form uses a pretty straightforward vertical layout, I suggest using the form_layout_vertical forms class plug-in. Take a look at the test_auto_layout_form.php example script. There is an even more productive plug-in for AJAX scaffolding that was just announced to be in beta. It needs documentation but it is certainly a giant leap forward in productivity that you may want to check out. phpclasses.org/blog/package/1/post/ ...
![]() Problem solved by the form_layout_vertical forms class plug-in
Thanks |
info at phpclasses dot org
.