Added new form type

This commit is contained in:
Antonio de la Rosa 2015-08-25 21:36:07 +02:00
parent 7ab106db62
commit 7be0c01588
5 changed files with 67 additions and 13 deletions

View file

@ -9,6 +9,7 @@
*/
namespace PhangoApp\PhaModels\CoreFields;
use PhangoApp\PhaModels\Forms\BaseForm;
use PhangoApp\PhaUtils\Utils;
class PasswordField extends CharField {
@ -63,6 +64,24 @@ class PasswordField extends CharField {
return false;
}
/**
* 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;
}
}

View file

@ -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;

View file

@ -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
@ -77,6 +78,23 @@ class PrimaryField extends PhangoField {
return $value;
}
/**
* 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;
}
}

View file

@ -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('"', '&quot;')
return str_replace('"', '&quot;', $value);
}
}

View file

@ -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,14 +1554,25 @@ class Webmodel {
}
$this->forms[$component_name]=$this->components[$component_name]->create_form();
$this->create_form($component_name);
}
}
}
/**
* 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