I know it seems kinda confusing but it really isn’t. I want to start coding using OOP.
I created a class named Form.
Form has a method to add text fields called addTextField.
Form has another method to add fieldsets called addFieldset.
I want to use the addTextField method inside the addFieldset method, since a fieldset is composed of several text fields.
Here is the code I have so far
class Form
{
// Declare a class member variable
var $form;
function addFormAttributes($urlQuery)
{
$urlQuery = trim($urlQuery);
if(!empty($urlQuery))
{
$urlQuery = '?'.$urlQuery;
}
$this->form .= '<form name="" action="'.$_SERVER['PHP_SELF'].$urlQuery.'" method="POST">';
}
// --- Operators/Methods/Functions/Actions ---
function addTextField($label, $name, $value, $tablename, $column, $validation='')
{
$_POST[$name] = trim($_POST[$name]);
if($validation == 'required')
{
$hint = '<em class="required">(required)</em>';
if(isset($_POST[$name]) && $_POST['process'] == 1 && empty($_POST[$name]))
{
$feedback = '<span class="formFeedback">This field is required</span>';
}
}
$this->form .= '<p><label for="'.$name.'">'.$label.' '.$hint.'</label><input type="text" name="'.$name.'" value="'.$value.'" />'.$feedback.'</p>';
$feedback='';
$hint='';
}
function addFieldset($legend, $fields)
{
$this->form .= '<fieldset><legend>'.$legend.'</legend>';
foreach($fields as $key => $value)
{
if($value[0]=='text')
{
$this->form .= addTextField($value[1], $value[2], $value[3], $value[4], $value[5]);
}
}
$this->form .= '</fieldset>';
}
function addSubmitButton($value)
{
$this->form .= '<p><input type="submit" value="'.$value.'"></p>';
}
// Gets the form
function get()
{
$this->form = $this->form.'<input type="hidden" name="process" value="1"></form>';
return $this->form;
}
}
It gives me this error message: “Fatal error: Call to undefined function: addtextfield()”
What does it mean “undefined function”? I did define it.