Fixes on PasswordForm

This commit is contained in:
Antonio de la Rosa 2015-08-26 00:32:20 +02:00
parent 528d5a2d48
commit 7dbe80697e
7 changed files with 76 additions and 18 deletions

View file

@ -76,6 +76,27 @@ class EmailField extends PhangoField {
return $value;
}
/**
* By default primaryfield use a hidden form
*/
public function create_form()
{
/*$form=new PasswordForm($this->name_component, $this->value);
$form->default_value=$this->default_value;
$form->required=$this->required;
$form->label=$this->label;
$form->type='password';*/
$form=parent::create_form();
$form->field=new EmailField();
return $form;
}
}

View file

@ -35,7 +35,6 @@ class ForeignKeyField extends IntegerField{
$this->fields_related_model=array();
//Representative field for related model...
$this->name_field_to_field='';
$this->null_relation=$null_relation;
$this->default_id=$default;
$this->quot_open='';
$this->quot_close='';

View file

@ -9,7 +9,7 @@
*/
namespace PhangoApp\PhaModels\CoreFields;
use PhangoApp\PhaModels\Forms\BaseForm;
use PhangoApp\PhaModels\Forms\PasswordForm;
use PhangoApp\PhaUtils\Utils;
class PasswordField extends CharField {
@ -72,7 +72,7 @@ class PasswordField extends CharField {
public function create_form()
{
$form=new BaseForm($this->name_component, $this->value);
$form=new PasswordForm($this->name_component, $this->value);
$form->default_value=$this->default_value;
$form->required=$this->required;
$form->label=$this->label;

View file

@ -29,9 +29,9 @@ class UserPhangoModel extends Webmodel {
public $password='password';
public $repeat_password='repeat_password';
public function insert($post)
public function insert($post, $safe_query=0)
{
if($this->check_user_exists($post[$this->username], $post[$this->email]))
{
@ -40,13 +40,13 @@ class UserPhangoModel extends Webmodel {
//$this->components['password']->required=0;
$this->components[$this->password]->std_error=I18n::lang('users', 'pasword_not_equal_repeat_password', 'Passwords are not equal');
$this->forms[$this->password]->std_error=I18n::lang('users', 'pasword_not_equal_repeat_password', 'Passwords are not equal');
return false;
}
return parent::insert($post);
return parent::insert($post, $safe_query);
}
else
@ -60,7 +60,7 @@ class UserPhangoModel extends Webmodel {
}
public function update($post, $where_sql='')
public function update($post, $safe_query=0)
{
if(isset($post[$this->username]) && $post[$this->email])
@ -74,7 +74,7 @@ class UserPhangoModel extends Webmodel {
//$this->components['password']->required=0;
$this->components[$this->password]->std_error=I18n::lang('users', 'pasword_not_equal_repeat_password', 'Passwords are not equal');
$this->forms[$this->password]->std_error=I18n::lang('users', 'pasword_not_equal_repeat_password', 'Passwords are not equal');
return false;
@ -88,7 +88,7 @@ class UserPhangoModel extends Webmodel {
}
return parent::update($post, $where_sql);
return parent::update($post, $safe_query);
}
else
@ -104,7 +104,7 @@ class UserPhangoModel extends Webmodel {
else
{
return parent::update($post, $where_sql);
return parent::update($post, $safe_query);
}
@ -144,7 +144,9 @@ class UserPhangoModel extends Webmodel {
}
$c=$this->select_count($where_sql);
$this->set_conditions($where_sql);
$c=$this->select_count();
if($c==0)
{

View file

@ -3,6 +3,7 @@
namespace PhangoApp\PhaModels\Forms;
use PhangoApp\PhaModels\CoreFields\CharField;
use PhangoApp\PhaI18n\I18n;
/**
* Basic class for create forms
@ -16,6 +17,8 @@ class BaseForm {
* @param string $name Field class instance used for check files
*/
public $std_error='';
public function __construct($name, $value)
{
$this->label=$name;
@ -25,6 +28,7 @@ class BaseForm {
$this->type='text';
$this->required=0;
$this->field=new CharField();
$this->txt_error = I18n::lang('common', 'error_in_field', 'Error in field');
}
public function form()

View file

@ -0,0 +1,32 @@
<?php
namespace PhangoApp\PhaModels\Forms;
use PhangoApp\PhaModels\Forms\BaseForm;
use PhangoApp\PhaModels\CoreFields\PasswordField;
/**
* Basic class for create forms
*/
class PasswordForm extends BaseForm{
public function __construct($name, $value='')
{
parent::__construct($name, $value);
$this->field=new PasswordField();
}
public function form()
{
return '<input type="password" class="'.$this->css.'" name="'.$this->name.'" value="">';
}
}
?>

View file

@ -318,21 +318,21 @@ class ModelForm {
$form=$arr_form[$key_form];
$post[$key_form]=$form->type->check($post[$key_form]);
$post[$key_form]=$form->field->check($post[$key_form]);
if($post[$key_form]=='' && $form->required==1)
{
if($form->type->std_error!='')
if($form->field->std_error!='')
{
$form->std_error=$form->type->std_error;
$form->std_error=$form->field->std_error;
}
else
{
$form->std_error=$form->txt_error;
$form->std_error=I18n::lang('common', 'field_required', 'Field is required');
}
@ -390,7 +390,7 @@ class ModelForm {
if(isset($arr_form[$name_field]))
{
if($arr_form[$name_field]->type->std_error!='' && $show_error==1)
if($arr_form[$name_field]->field->std_error!='' && $show_error==1)
{
/*if($arr_form[$name_field]->std_error!='')
@ -412,7 +412,7 @@ class ModelForm {
//Set value for ModelForm to $value
$arr_form[$name_field]->set_param_value_form($value);
$arr_form[$name_field]->default_value=$value;
}
else