Using the PHP Form Builder Class (PFBC) within your own Joomla Component.
Why?
I was in the need of professional forms for a Joomla component I’m currently writing. With “professional” I mean the forms have to look professional and also need to be validated in a professional manner. I first went through a lot of Javascript/CSS solutions. However, in the back of my mind I thought I still have to validate all input on the Server level (Within the Joomla component itself) Finally I found an actively maintained Forms Library that after some testing worked great within any Joomla Component.
Here are some basic notes on how I accomplished this:
I’m using a file called loader.php located in the library path in my component Directory. I call it from my main controller file like this:
require_once(JPATH_ROOT.DS.'components'.DS.'com_component'.DS.'library'.DS.'loader.php');
in my loader PHP I have this line:
JLoader::register('Form', JPATH_COMPONENT.'/3rdparty/PFBC/Form.php');
As you can see I just copied the PFBC folder into a folder called 3rdparty within my Joomla component folder. Now you can use PFBC anywhere in your component by creating the object like this and add a field for example:
$form = new Form("testing", 300) ; $form->addElement(new Element_Textbox("My Textbox:", "MyTextbox")); $form->addElement(new Element_Button);
Assign it to the View as usual:
$this->assignRef('myform', $form);
And render it in the tmpl file:
echo $this->myform->render();
Recent Comments