File: /var/www/vhosts/creativefellows.nl/jhtaxatie.creativefellows.nl/classes/FormData.php
<?php
final class FormData
{
protected $fields = [];
protected $action = "";
protected $method = "post";
protected $enctype = "multipart/form-data";
protected $form_error_message = "The form cannot be processed. The fields marked in contain values that we do not understand.";
protected $role = null;
function __construct(array $fields, array $post_data=[],$role = 0)
{
$this->setRole($role);
foreach($fields as $group => $field)
{
$formField = new HtmlElement($field,$this->role);
$formField->setPostValue( $post_data[$formField->id()] );
$this->setField( $formField );
}
}
public function action()
{
return $this->action;
}
public function setAction($action)
{
$this->action = $action;
}
public function setField($field)
{
$this->fields[] = $field;
}
public function setRole($role)
{
$this->role = $role;
}
public function fields()
{
return $this->fields;
}
public function open()
{
return '<form action="'. $this->action() .'" method="post" class="default-form" enctype="'. $this->enctype .'" data-abide novalidate>';
}
public function fieldsHTML($confirm=false)
{
$html = '<div class="grid-x grid-margin-x">';
foreach($this->fields as $field)
{
$html.= $field->getInputElement();
}
$html .= $this->formError();
$html .= '</div>';
return $html;
}
public function close()
{
return '</form>';
}
private function formError()
{
return '';//'<div class="small-12 cell"><div data-abide-error class="callout alert text-center" aria-live="assertive" style="display: none;"><p><i class="fi-alert"></i> '. $this->form_error_message .'</p></div>';
}
}