112 lines
2.3 KiB
PHP
112 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace PhangoApp\PhaForms\Forms;
|
|
|
|
/**
|
|
* Basic class for create forms
|
|
*/
|
|
|
|
class BaseForm {
|
|
|
|
/**
|
|
* @param string $name The name of form
|
|
* @param string $name The default value of the form
|
|
* @param string $name Field class instance used for check files
|
|
*/
|
|
|
|
public $std_error='';
|
|
|
|
/**
|
|
* A property for add enctype for a form where this field is used
|
|
*/
|
|
|
|
public $enctype=0;
|
|
public $label='';
|
|
public $name='';
|
|
public $default_value='';
|
|
public $css='';
|
|
public $type='text';
|
|
public $required=0;
|
|
public $field;
|
|
public $comment_form='';
|
|
public $code_error=0;
|
|
public $txt_error='';
|
|
public $extra_param='';
|
|
public $parameters=[];
|
|
public $label_class='';
|
|
public $form;
|
|
public $placeholder='';
|
|
public $help='';
|
|
|
|
public function __construct($name, $value, $extra_parameters=array())
|
|
{
|
|
$this->label=$name;
|
|
$this->name=$name;
|
|
$this->default_value=$value;
|
|
$this->css='';
|
|
$this->type='text';
|
|
$this->required=0;
|
|
$this->comment_form='';
|
|
$this->txt_error = _('Error in field');
|
|
$this->extra_param='';
|
|
}
|
|
|
|
public function form()
|
|
{
|
|
|
|
return '<input type="'.$this->type.'" id="'.$this->name.'_field_form" class="'.$this->css.'" name="'.$this->name.'" value="'.$this->setform($this->default_value).'" '.$this->extra_param.' placeholder="'.$this->placeholder.'"> '.$this->comment_form;
|
|
|
|
}
|
|
|
|
public function set_parameters(array $parameters)
|
|
{
|
|
|
|
foreach($parameters as $property => $value)
|
|
{
|
|
|
|
$this->$property=$value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* Static method where is registered the js necessary for a field
|
|
*/
|
|
|
|
static public function js()
|
|
{
|
|
|
|
}
|
|
|
|
/**
|
|
* Static method where is registered the css necessary for a field
|
|
*/
|
|
|
|
static public function css()
|
|
{
|
|
|
|
}
|
|
|
|
/**
|
|
* Static method where is registered other headers for the form.
|
|
*/
|
|
|
|
static public function header()
|
|
{
|
|
|
|
}
|
|
|
|
/**
|
|
* Method for escape value for html input
|
|
*/
|
|
|
|
public function setform($value)
|
|
{
|
|
|
|
return trim(htmlspecialchars($value));
|
|
|
|
}
|
|
}
|
|
|
|
?>
|