Added new form type
This commit is contained in:
parent
7ab106db62
commit
7be0c01588
5 changed files with 67 additions and 13 deletions
|
|
@ -9,6 +9,7 @@
|
|||
*/
|
||||
|
||||
namespace PhangoApp\PhaModels\CoreFields;
|
||||
use PhangoApp\PhaModels\Forms\BaseForm;
|
||||
use PhangoApp\PhaUtils\Utils;
|
||||
|
||||
class PasswordField extends CharField {
|
||||
|
|
@ -64,6 +65,24 @@ class PasswordField extends CharField {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* By default primaryfield use a hidden form
|
||||
*/
|
||||
|
||||
public function create_form()
|
||||
{
|
||||
|
||||
$form=new BaseForm($this->name_component, $this->value);
|
||||
$form->default_value=$this->default_value;
|
||||
$form->required=$this->required;
|
||||
$form->label=$this->label;
|
||||
$form->type='password';
|
||||
|
||||
return $form;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -172,7 +172,7 @@ class PhangoField {
|
|||
public function create_form()
|
||||
{
|
||||
|
||||
$form=new BaseForm($this->name, $this->value);
|
||||
$form=new BaseForm($this->name_component, $this->value);
|
||||
$form->default_value=$this->default_value;
|
||||
$form->required=$this->required;
|
||||
$form->label=$this->label;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace PhangoApp\PhaModels\CoreFields;
|
||||
use PhangoApp\PhaUtils\Utils;
|
||||
use PhangoApp\PhaModels\Forms\BaseForm;
|
||||
|
||||
/**
|
||||
* PrimaryField is used for primary keys for models
|
||||
|
|
@ -78,6 +79,23 @@ class PrimaryField extends PhangoField {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* By default primaryfield use a hidden form
|
||||
*/
|
||||
|
||||
public function create_form()
|
||||
{
|
||||
|
||||
$form=new BaseForm($this->name_component, $this->value);
|
||||
$form->default_value=$this->default_value;
|
||||
$form->required=$this->required;
|
||||
$form->label=$this->label;
|
||||
$form->type='hidden';
|
||||
|
||||
return $form;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace PhangoApp\PhaModels\Forms;
|
||||
|
||||
use PhangoApp\PhaModels\CoreFields\CharField;
|
||||
|
||||
/**
|
||||
* Basic class for create forms
|
||||
*/
|
||||
|
|
@ -14,29 +16,32 @@ class BaseForm {
|
|||
* @param string $name Field class instance used for check files
|
||||
*/
|
||||
|
||||
public function __construct($name, $value, $field)
|
||||
public function __construct($name, $value)
|
||||
{
|
||||
$this->label=name;
|
||||
$this->name=name;
|
||||
$this->default_value=value;
|
||||
$this->label=$name;
|
||||
$this->name=$name;
|
||||
$this->default_value=$value;
|
||||
$this->css='';
|
||||
$this->type='text';
|
||||
$this->required=0;
|
||||
$this->field=new CharField();
|
||||
}
|
||||
|
||||
public function form()
|
||||
{
|
||||
|
||||
return '<input type="'.$this->type.'" class="'.$this->css.'" name="'.$this->setform($this->default_value).'">';
|
||||
return '<input type="'.$this->type.'" class="'.$this->css.'" name="'.$this->name.'" value="'.$this->setform($this->default_value).'">';
|
||||
|
||||
}
|
||||
|
||||
#Method for escape value for html input
|
||||
/**
|
||||
* Method for escape value for html input
|
||||
*/
|
||||
|
||||
public function setform(value)
|
||||
public function setform($value)
|
||||
{
|
||||
|
||||
return value.replace('"', '"')
|
||||
return str_replace('"', '"', $value);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -296,6 +296,8 @@ class Webmodel {
|
|||
$this->name=$name_model;
|
||||
$this->idmodel='Id'.ucfirst($this->name);
|
||||
$this->components[$this->idmodel]=new PrimaryField();
|
||||
$this->components[$this->idmodel]->name_model=$name_model;
|
||||
$this->components[$this->idmodel]->name_component=$this->idmodel;
|
||||
$this->label=$this->name;
|
||||
|
||||
if(!isset(Webmodel::$connection_func[$this->db_selected]))
|
||||
|
|
@ -1331,7 +1333,7 @@ class Webmodel {
|
|||
if(count($this->forms)==0)
|
||||
{
|
||||
|
||||
$this->create_form();
|
||||
$this->create_forms();
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1539,7 +1541,6 @@ class Webmodel {
|
|||
|
||||
}
|
||||
|
||||
//foreach($this->components as $component_name => $component)
|
||||
foreach($fields_form as $component_name)
|
||||
{
|
||||
|
||||
|
|
@ -1553,8 +1554,7 @@ class Webmodel {
|
|||
|
||||
}
|
||||
|
||||
$this->forms[$component_name]=$this->components[$component_name]->create_form();
|
||||
|
||||
$this->create_form($component_name);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1562,6 +1562,18 @@ class Webmodel {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for create a simple form from a field
|
||||
* @param string $component_name The name of the component that is used for create the form
|
||||
*/
|
||||
|
||||
public function create_form($component_name)
|
||||
{
|
||||
|
||||
$this->forms[$component_name]=$this->components[$component_name]->create_form();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for obtain an array with all errors in components
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue