Hi All,
Rather than building my own form class, I have downloaded the PFBC form class
I have not come across namespaces before, and am a bit shaky when it comes to OOP. I did try to read up on namespaces, and have some basic understanding the concept. But clearly I am missing some fundamentals, and have run into trouble.
I got the basics running just fine, and have managed to implement the login form example as a dry run.
Now I would like to create my own methods for using the PFBC class: I have a few forms that I would like to use across the site, and it is easier to just prepare the form in a class method, rather than inline in the code.
I have created a new class, which uses the PFBC example code, and the handle:
<?php
namespace PFBC;
class jf_form
{
public function __construct($formlink)
{
$this->form = $formlink;
}
function login_form()
{
$this->form->addElement(new Element\HTML('<legend>Login</legend>'));
$this->form->addElement(new Element\Hidden("form", "login"));
$this->form->addElement(new Element\Email("Email Address:", "Email", array(
"required" => 1
)));
$this->form->addElement(new Element\Password("Password:", "Password", array(
"required" => 1
)));
$this->form->addElement(new Element\Checkbox("", "Remember", array(
"1" => "Remember me"
)));
$this->form->addElement(new Element\Button("Login"));
$this->form->addElement(new Element\Button("Cancel", "button", array(
"onclick" => "history.go(-1);"
)));
$this->form->render();
}
}
?>
And I tried calling it from the script:
$form = new Form("login");
$formi = new jf_form($form);
$formi->login_form();
This results in Fatal error: Class 'Jf_form' not found in
I have also tried without the namespace keyword on top. The class then loads, but as soon as it reaches the first addelement statement, the script fails, stating it does not know the class Element HTML.
I have tried this with the jf_form class file both in my normal pre-loaded classes directory, as well as in the PCB sub-directory.
Clearly, I am missing something here, but I am not sure what.
What would be the best way to go about this? Can somebody please help me on this 🙁